如何通过c#SMTP发送电子邮件

时间:2015-06-30 20:33:55

标签: c#

我想通过C#发送电子邮件,我怎么能以正确的方式做到这一点?我应该用

System.Net.Mail
MailMessage mail = new MailMessage();

现在?

1 个答案:

答案 0 :(得分:1)

SmtpClient SmtpServer = new SmtpClient("mail.provider.com.br");
mail.From = new MailAddress("noreply@provider.com.br");
mail.To.Add("youremail@provider.com.br");
mail.Subject = "Some title";
mail.Body = "YOUR TEXT GOES HERE";
SmtpServer.Port = 'port';
//credentials
SmtpServer.Credentials = new System.Net.NetworkCredential("youremail@provider.com.br", "pa$$word");
SmtpServer.Send(mail);