用C#发送电子邮件 [英] send email in c#
本文介绍了用C#发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用此代码发送电子邮件..但 smtp.Send(mail)中发生错误;消息发送邮件失败"
i've tried to send email using this code..but an error occurred in smtp.Send(mail); messaging "Failure sending mail"
MailMessage mail = new MailMessage();
// set the addresses
mail.From = new MailAddress("from@gmail.com");
mail.To.Add(new MailAddress("to@yahoo.com"));
// set the content
mail.Subject = "test sample";
mail.Body = @"thank you";
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.Credentials = new NetworkCredential("from@gmail.com", "password");
smtp.Send(mail);
推荐答案
在您的代码中指定端口号:
In your code specify port number:
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587)
也请查看此线程通过Gmail SMTP服务器发送电子邮件使用C#
这篇关于用C#发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文