Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

c# Send email using visual studio 2015

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("[email protected]", "password");
try
{
    cv.Send("[email protected]", "[email protected]", "", "Hello");
    MessageBox.Show("Done");
}
catch(Exception w)
{
    MessageBox.Show("Not send" + w.InnerException);
}  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you must figured out that setting the SmtpClient Credentials property before setting the UseDefaultCredentials = false causes the credentials to be ignored.

fails:

SmtpClient smtp = new SmtpClient;
smtp.Credentials = new NetworkCredential("[email protected]","pass");
smtp.UseDefaultCredentials = false;

Works:

SmtpClient smtp = new SmtpClient;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("[email protected]","pass");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...