c#发送邮件样例

1.通过gmail邮箱发送邮件

try
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

    mail.From = new MailAddress("username@gmail.com");
    mail.To.Add("receiver@qq.com");
    mail.Subject = "Test Mail";
    mail.Body = "This is for testing SMTP mail from GMAIL";

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
    MessageBox.Show("mail Send");
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

原文地址:https://www.cnblogs.com/jerry1999/p/4175916.html