/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public Task<List<EmailResult>> SendMessageAsync(IEnumerable<EmailAddress> recipients, string subject, string content, EmailAddress from) { var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, html = content, auto_text = true, }; return SendMessageAsync(message); }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public Task<List<EmailResult>> SendMessageAsync(IEnumerable<EmailAddress> recipients, string subject, string content, EmailAddress from) { var path = "/messages/send.json"; var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, html = content, auto_text = true, }; dynamic payload = new ExpandoObject(); payload.message = message; Task<IRestResponse> post = PostAsync(path, payload); return post.ContinueWith(p => { return JSON.Parse<List<EmailResult>>(p.Result.Content); }, TaskContinuationOptions.ExecuteSynchronously); }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="from"></param> /// <param name="templateName"></param> /// <param name="templateContents"></param> /// <returns></returns> public List<EmailResult> SendMessage(IEnumerable<EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable<TemplateContent> templateContents) { return SendMessageAsync(recipients, subject, from, templateName, templateContents).Result; }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public List<EmailResult> SendMessage(IEnumerable<EmailAddress> recipients, string subject, string content, EmailAddress from) { return SendMessageAsync(recipients, subject, content, from).Result; }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="from"></param> /// <param name="templateName"></param> /// <param name="templateContents"></param> /// <returns></returns> public Task<List<EmailResult>> SendMessageAsync(IEnumerable<EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable<TemplateContent> templateContents) { var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, }; return SendMessageAsync(message, templateName, templateContents); }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"> /// </param> /// <param name="subject"> /// </param> /// <param name="from"> /// </param> /// <param name="templateName"> /// </param> /// <param name="templateContents"> /// </param> /// <param name="send_at"> /// The send_at. /// </param> /// <returns> /// The <see cref="List" />. /// </returns> public List<EmailResult> SendMessage( IEnumerable<EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable<TemplateContent> templateContents, DateTime send_at = new DateTime()) { return this.SendMessageAsync(recipients, subject, from, templateName, templateContents, send_at).Result; }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"> /// </param> /// <param name="subject"> /// </param> /// <param name="content"> /// </param> /// <param name="from"> /// </param> /// <param name="send_at"> /// The send_at. /// </param> /// <returns> /// The <see cref="List" />. /// </returns> public List<EmailResult> SendMessage( IEnumerable<EmailAddress> recipients, string subject, string content, EmailAddress from, DateTime send_at = new DateTime()) { return SendMessageAsync(recipients, subject, content, from, send_at).Result; }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="from"></param> /// <param name="templateName"></param> /// <param name="templateContents"></param> /// <returns></returns> public Task <List <EmailResult> > SendTemplateAsync(IEnumerable <EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable <TemplateContent> templateContents) { var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, }; return(SendTemplateAsync(message, templateName, templateContents)); }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="from"></param> /// <param name="templateName"></param> /// <param name="templateContents"></param> /// <returns></returns> public List <EmailResult> SendTemplate(IEnumerable <EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable <TemplateContent> templateContents) { return(SendTemplateAsync(recipients, subject, from, templateName, templateContents).Result); }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public Task <List <EmailResult> > SendAsync(IEnumerable <EmailAddress> recipients, string subject, string content, EmailAddress from) { var path = "/messages/send.json"; var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, html = content, auto_text = true, }; dynamic payload = new ExpandoObject(); payload.message = message; Task <IRestResponse> post = PostAsync(path, payload); return(post.ContinueWith(p => { return JSON.Parse <List <EmailResult> >(p.Result.Content); }, TaskContinuationOptions.ExecuteSynchronously)); }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public List <EmailResult> Send(IEnumerable <EmailAddress> recipients, string subject, string content, EmailAddress from) { return(SendAsync(recipients, subject, content, from).Result); }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="content"></param> /// <param name="from"></param> /// <returns></returns> public Task <List <EmailResult> > SendMessageAsync(IEnumerable <EmailAddress> recipients, string subject, string content, EmailAddress from) { var message = new EmailMessage() { to = recipients, from_name = from.name, from_email = from.email, subject = subject, html = content, auto_text = true, }; return(SendMessageAsync(message)); }
private void SendSingleMail(string email_subject, string email_body, IEnumerable<string> email_list, MandrillApi mandrill, List<UDT.MandrillSendLog> MandrillSendLogs, dynamic o, StudentRecord Student, bool IsCC) { if (email_list.Count() == 0) return; string current_email = string.Empty; try { // gmail 改為 mandrill //System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); //System.Net.NetworkCredential cred = new System.Net.NetworkCredential(this.SenderEmail, this.SenderPassword); //mail.Subject = email_subject; //mail.From = new System.Net.Mail.MailAddress(this.SenderEmail); //foreach (string email_address in email_list) // mail.To.Add(email_address); //mail.IsBodyHtml = true; //mail.Body = email_body; //System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //smtp.UseDefaultCredentials = false; //smtp.EnableSsl = true; //smtp.Credentials = cred; //smtp.Port = 587; //smtp.Send(mail); //mandrill = new MandrillApi(this.MandrillAPIKey, false); List<EmailAddress> EmailAddresss = new List<EmailAddress>(); foreach (string mail_to in email_list) { current_email = mail_to; EmailMessage message = new EmailMessage(); message.auto_text = false; message.from_email = this.from_email; message.from_name = this.from_name; EmailAddress mt = new EmailAddress(); mt.email = mail_to; mt.name = string.Empty; message.to = new List<EmailAddress>(){ mt }; message.track_clicks = false; message.track_opens = false; message.html = email_body; message.important = false; message.merge = false; message.preserve_recipients = false; message.subject = email_subject; List<EmailResult> results = mandrill.SendMessageSync(message); // Log Email Result foreach (EmailResult result in results) { UDT.MandrillSendLog MandrillSendLog = new UDT.MandrillSendLog(); if (Student != null) { MandrillSendLog.StudentID = int.Parse(Student.ID); MandrillSendLog.StudentNumber = Student.StudentNumber; MandrillSendLog.StudentName = Student.Name; } MandrillSendLog.CourseID = int.Parse(o.CourseID + ""); MandrillSendLog.CourseName = o.CourseName + ""; MandrillSendLog.SubjectID = int.Parse(o.SubjectID + ""); MandrillSendLog.SubjectName = o.SubjectName + ""; MandrillSendLog.TeacherID = int.Parse(o.TeacherID + ""); MandrillSendLog.TeacherName = o.TeacherName + ""; MandrillSendLog.SchoolYear = o.SchoolYear + ""; MandrillSendLog.Semester = o.Semester + ""; MandrillSendLog.SurveyBeginTime = o.SurveyBeginTime + ""; MandrillSendLog.SurveyEndTime = o.SurveyEndTime + ""; MandrillSendLog.IsCC = IsCC; MandrillSendLog.CCEmailAddress = string.Empty; MandrillSendLog.CurrentUserAccount = this.user_account; MandrillSendLog.Device = "desktop"; MandrillSendLog.EmailCategory = this.email_category; MandrillSendLog.GUID = this.guid; MandrillSendLog.RecipientEmailAddress = mail_to;// string.Join(",", email_list); MandrillSendLog.RejectReason = result.RejectReason; MandrillSendLog.ResultEmail = result.Email; MandrillSendLog.ResultID = result.Id; MandrillSendLog.SenderEmailAddress = this.from_email; MandrillSendLog.SenderName = this.from_name; MandrillSendLog.TimeStamp = this.time_stamp; MandrillSendLog.Source = string.Empty; MandrillSendLogs.Add(MandrillSendLog); } //EmailAddresss.Add(mt); } } // Log Email Error catch (Exception ex) { MandrillException error = (MandrillException)ex; UDT.MandrillSendLog MandrillSendLog = new UDT.MandrillSendLog(); if (Student != null) { MandrillSendLog.StudentID = int.Parse(Student.ID); MandrillSendLog.StudentNumber = Student.StudentNumber; MandrillSendLog.StudentName = Student.Name; } MandrillSendLog.CourseID = int.Parse(o.CourseID + ""); MandrillSendLog.CourseName = o.CourseName + ""; MandrillSendLog.SubjectID = int.Parse(o.SubjectID + ""); MandrillSendLog.SubjectName = o.SubjectName + ""; MandrillSendLog.TeacherID = int.Parse(o.TeacherID + ""); MandrillSendLog.TeacherName = o.TeacherName + ""; MandrillSendLog.SchoolYear = o.SchoolYear + ""; MandrillSendLog.Semester = o.Semester + ""; MandrillSendLog.SurveyBeginTime = o.SurveyBeginTime + ""; MandrillSendLog.SurveyEndTime = o.SurveyEndTime + ""; MandrillSendLog.IsCC = IsCC; MandrillSendLog.CCEmailAddress = string.Empty; MandrillSendLog.CurrentUserAccount = this.user_account; MandrillSendLog.Device = "desktop"; MandrillSendLog.EmailCategory = this.email_category; MandrillSendLog.GUID = this.guid; MandrillSendLog.RecipientEmailAddress = current_email;// string.Join(",", email_list); MandrillSendLog.ErrorCode = error.Error.code; MandrillSendLog.ErrorMessage = error.Error.message; MandrillSendLog.ErrorName = error.Error.name; MandrillSendLog.ErrorStatus = error.Error.status; MandrillSendLog.SenderName = this.from_name; MandrillSendLog.SenderEmailAddress = this.from_email; MandrillSendLog.TimeStamp = this.time_stamp; MandrillSendLog.Source = error.ToString(); MandrillSendLogs.Add(MandrillSendLog); } }
/// <summary> /// Send a new transactional message through Mandrill using a template /// </summary> /// <param name="recipients"></param> /// <param name="subject"></param> /// <param name="from"></param> /// <param name="templateName"></param> /// <param name="templateContents"></param> /// <returns></returns> public List <EmailResult> SendMessage(IEnumerable <EmailAddress> recipients, string subject, EmailAddress from, string templateName, IEnumerable <TemplateContent> templateContents, DateTime send_at = new DateTime()) { return(SendMessageAsync(recipients, subject, from, templateName, templateContents, send_at).Result); }
private void SendSingleMail(MailLog MailLog, IEnumerable<string> email_list, MandrillApi mandrill, List<UDT.MailLog> MandrillSendLogs) { if (email_list.Count() == 0) return; try { EmailMessage message = new EmailMessage(); message.auto_text = true; message.from_email = this.from_email; message.from_name = this.from_name; List<EmailAddress> EmailAddresss = new List<EmailAddress>(); foreach (string mail_to in email_list) { EmailAddress mt = new EmailAddress(); mt.email = mail_to; mt.name = string.Empty; EmailAddresss.Add(mt); } message.to = EmailAddresss; message.track_clicks = true; message.track_opens = true; message.html = MailLog.MailContent; message.important = true; message.merge = false; message.preserve_recipients = true; message.subject = MailLog.MailSubject; MailLog.TimeStamp = DateTime.Now; List<EmailResult> results = mandrill.SendMessageSync(message); // Log Email Result foreach (EmailResult result in results) { MailLog.Result = "<Result>" + "<NoneException>" + "<Status>" + result.Status.ToString() + "</Status>" + "<ResultID>" + result.Id + "</ResultID>" + "<Email>" + result.Email + "</Email>" + "<RejectReason>" + result.RejectReason + "</RejectReason>" + "</NoneException>" + "</Result>"; MailLog.RecipientEmailAddress = result.Email; MailLog.Status = result.Status.ToString(); this.Log(MailLog, MandrillSendLogs); } } // Log Email Error catch (Exception ex) { MandrillException error = (MandrillException)ex; MailLog.Result = "<Result>" + "<Exception>" + "<Status>" + error.Error.status + "</Status>" + "<Code>" + error.Error.code + "</Code>" + "<Name>" + error.Error.name + "</Name>" + "<Message>" + error.Message + "</Message>" + "<Source>" + error.Source + "</Source>" + "<Email></Email>" + "</Exception>" + "</Result>"; MailLog.RecipientEmailAddress = string.Empty; MailLog.Status = error.Error.status; this.Log(MailLog, MandrillSendLogs); } }
/// <summary> /// Send a new transactional message through Mandrill. /// </summary> /// <param name="recipients"> /// </param> /// <param name="subject"> /// </param> /// <param name="content"> /// </param> /// <param name="from"> /// </param> /// <param name="send_at"> /// The send_at. /// </param> /// <returns> /// The <see cref="List" />. /// </returns> public List <EmailResult> SendMessage(IEnumerable <EmailAddress> recipients, string subject, string content, EmailAddress from, DateTime?send_at = null) { return(SendMessageAsync(recipients, subject, content, from, send_at).Result); }