Beispiel #1
0
 public bool Send(MailEntity mailEntity)
 {
     try
     {
         MailMessage message = new MailMessage();
         message.BodyEncoding    = Encoding.UTF8;
         message.HeadersEncoding = Encoding.UTF8;
         message.SubjectEncoding = Encoding.UTF8;
         message.IsBodyHtml      = true;
         message.Subject         = mailEntity.subject;
         message.From            = new MailAddress(this.smtp_sender);
         message.Body            = mailEntity.body;
         message.To.Add(mailEntity.to);
         SmtpClient smtp = new SmtpClient(this.smtp_host);
         smtp.Credentials = new NetworkCredential(this.smtp_sender, this.smtp_password);
         smtp.EnableSsl   = true;
         smtp.Port        = this.smtp_port;
         smtp.Send(message);
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Debug.WriteLine(ex.Message);
         return(false);
     }
 }
Beispiel #2
0
 public Task <bool> SendAsync(MailEntity mailEntity)
 {
     return(Task.Run(() => Send(mailEntity)));
 }