C#使用Visual Studio 2015发送电子邮件 [英] c# Send email using visual studio 2015
本文介绍了C#使用Visual Studio 2015发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Windows PC上使用Visual Studio 2015发送电子邮件。我正在使用Outlook电子邮件地址发送电子邮件,请有人帮我确保代码的正确性。我尝试了许多方法,但是它们要么超时,要么说它们无法发送失败以发送电子邮件。请帮助
I am trying to send an email using visual studio 2015 on a windows pc. i amusing a outlook email adress to send the emails please can somebody help me get the code rigth. i have tried many methods but they either timeout or say that they caanot send failure to send email. Please help
SmtpClient cv = new SmtpClient("smtp.live.com", 25);
cv.EnableSsl = true;
cv.Credentials = new NetworkCredential("xxxemail@mail.com", "password");
try
{
cv.Send("xxxemail@mail.com", "xxxanotheremail@mail.com", "", "Hello");
MessageBox.Show("Done");
}
catch(Exception w)
{
MessageBox.Show("Not send" + w.InnerException);
}
推荐答案
您必须弄清楚该设置设置 UseDefaultCredentials = false
之前的SmtpClient Credentials属性会导致忽略凭据。
you must figured out that setting the SmtpClient Credentials property before setting the UseDefaultCredentials = false
causes the credentials to be ignored.
失败:
SmtpClient smtp = new SmtpClient;
smtp.Credentials = new NetworkCredential("richardteunen2@hotmail.com","pass");
smtp.UseDefaultCredentials = false;
作品:
SmtpClient smtp = new SmtpClient;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("richardteunen2@hotmail.com","pass");
这篇关于C#使用Visual Studio 2015发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文