Winforms发送邮件

    // 首先开启smtp服务
    try
    {
        MailMessage message = new MailMessage();
        SmtpClient smtp = new SmtpClient();

        message.From = new MailAddress("from@domain.com");
        message.To.Add(new MailAddress("to@domain.com"));
        message.Subject = "Subject";
        message.Body = "Hello World";

        smtp.Port = 587;
        smtp.Host = "smtp.domain.com";
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = new NetworkCredential("from@domain.com", "password");
        smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        smtp.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
posted @ 2019-07-03 10:54  Kyle0418  阅读(127)  评论(0编辑  收藏  举报