public async Task sendMail(IdentityMessage message) { #region formatter string text = string.Format("Please click on this link to {0}: {1}", message.Subject, message.Body); string html = message.Body + "<br/>"; html += HttpUtility.HtmlEncode(@"Or click on the copy the following link on the browser:" + message.Body); #endregion MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**","Microbrew.it"); msg.To.Add(new MailAddress(message.Destination)); msg.Subject = message.Subject; msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain)); msg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html)); SmtpClient smtpClient = new SmtpClient("mail.gandi.net", Convert.ToInt32(587)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", MailPassword); smtpClient.Credentials = credentials; smtpClient.EnableSsl = true; smtpClient.Send(msg); using (ImapClient Client = new ImapClient("access.mail.gandi.net", 993, "*****@*****.**", MailPassword, AuthMethod.Login, true)) { Client.StoreMessage(msg, true, "Sent"); } }
public static void SaveMail2SentFolder(string subject, string body, EmailSettings settings) { using (ImapClient imap = new ImapClient(settings.SentHost, settings.SentPort, settings.SentLogin, settings.SentPassword, AuthMethod.Auto, settings.SentEnableSsl)) { MailMessage message = new MailMessage(); if (!String.IsNullOrEmpty(settings.SentLogin)) { message.From = new MailAddress(settings.SentLogin); } else { message.From = settings.MailFrom; } message.To.Add(settings.MailTo); message.Subject = subject; message.Body = body; string mailbox = null; foreach (var mb in imap.ListMailboxes()) { if (mb.ToLower().Equals("sent") || mb.ToLower().Equals("отправленные") || mb.ToLower().Contains("sent")) { mailbox = mb; break; } } uint uid = imap.StoreMessage(message, false, mailbox); //imap.SetMessageFlags(uid, null, ); } }