实例如下:

public void SendMail(string from, string to,
                     string subject, string body)
        {
            string mailServerName = "smtp.test.com";
            try
            {
                //MailMessage represents the e-mail being sent
                using (MailMessage message = new MailMessage(from,
                       to, subject, body))
                {
                    message.IsBodyHtml = true;
                    SmtpClient mailClient = new SmtpClient();
                    mailClient.Host = mailServerName;
                    mailClient.UseDefaultCredentials = true;
                    mailClient.DeliveryMethod =
                       SmtpDeliveryMethod.PickupDirectoryFromIis;
                    //Send delivers the message to the mail server
                    mailClient.Send(message);
                }
            }
            catch (SmtpException ex)
            {
                throw new ApplicationException
                   ("SmtpException has oCCured: " + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

 

来源:

Send Mails from within a .NET 2.0 Application

http://www.codeguru.com/csharp/csharp/cs_misc/e-mail/article.php/c9957

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2022-12-23
  • 2022-01-18
  • 2022-02-20
  • 2021-05-15
  • 2021-10-11
相关资源
相似解决方案