예제 #1
0
    public void Deliver(string to, string from, string subject, string body)
    {
      SmtpMail mailer = new SmtpMail();
      StringWriter smtpLog = new StringWriter(new StringBuilder());
      mailer.sw = smtpLog;
      MailMessage message = new MailMessage(from, to);
      message.Subject = subject;
      if (!_sendAsAttachments)
      {
        message.Body = body;
        message.IsBodyHtml = true;
      }
      else
      {
        message.Body = "The wiki has been updated. See the attached files for changes."; 
      }

      string success = null;
      try
      {
        if (!_sendAsAttachments)
        { 
          success = mailer.Send(message, _smtpHost, _smtpUser, _smtpPassword);
        }
        else
        {
          Hashtable atts = new Hashtable(); 
          atts.Add("Changes.htm", System.Text.Encoding.UTF8.GetBytes(body)); 
          success = mailer.Send(message, _smtpHost, _smtpUser, _smtpPassword, atts); 
        }
      }
      catch (Exception e)
      {
        Log.WriteLine("Exception while sending to host '" + _smtpHost + "': " + e.ToString());
      }
      if (success == null)
      {
        Log.WriteLine("SMTP deliver succeeded to: " + to);
      }
      else
      {
        Log.WriteLine("SMTP deliver failed to: " + to);
        Log.Write(smtpLog.ToString());
      }
    }
예제 #2
0
 protected string SendMail(System.Net.Mail.MailMessage message)
 {
     SmtpMail mailer = new SmtpMail();
     try
     {
         return mailer.Send(message, ConfigurationManager.AppSettings["SMTPServer"], ConfigurationManager.AppSettings["SMTPUser"], ConfigurationManager.AppSettings["SMTPPassword"]);
     }
     catch (Exception e)
     {
         return "An exception occurred trying to send mail. " + e.ToString();
     }
 }