Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
}  
See Question&Answers more detail:os

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

1 Answer

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("richardteunen2@hotmail.com","pass");
smtp.UseDefaultCredentials = false;

Works:

SmtpClient smtp = new SmtpClient;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("richardteunen2@hotmail.com","pass");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...