public ActionResult Index(SimpleMail data) { if (ModelState.IsValid) { //Create MailMessage MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(data.To); mail.Subject = data.Subject; mail.Body = data.Body; mail.SubjectEncoding = Encoding.UTF8; mail.BodyEncoding = Encoding.UTF8; mail.IsBodyHtml = true; //Create SMTP for send mail SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("lehoanghai22", "yeumynhju1"); smtp.EnableSsl = true; //Call Send mail -> Check all Spam smtp.Send(mail); return(RedirectToAction("Success")); } return(View(data)); }
public bool SendEmail(string username, string password, string subject, string fromaddress, string toaddress, string cc, string bcc, string body, bool isbodyhtml, string smtp) { if (username == ConfigurationManager.AppSettings["mailserviceuser"] && password == ConfigurationManager.AppSettings["mailservicepwd"]) { HarperLINQ.SimpleMail mail = new SimpleMail(); try { mail.bccemail = bcc; mail.body = body; mail.ccemail = cc; mail.datecreated = DateTime.Now; mail.fromemail = fromaddress; mail.isHtml = isbodyhtml; mail.ishtml = isbodyhtml; mail.smtpAddress = smtp; mail.subject = subject; mail.toemail = toaddress; using (AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString)) { context.SimpleMails.InsertOnSubmit(mail); context.SubmitChanges(); } return(true); } catch { return(false); } } else { return(false); } }
public async Task SendMessage(SimpleMail simpleMail) { var message = new MimeMessage(); message.To.AddRange(simpleMail.To.Select(m => new MailboxAddress(m))); message.From.Add(new MailboxAddress(simpleMail.From)); message.Subject = simpleMail.Subject; message.Body = new TextPart(TextFormat.Plain) { Text = simpleMail.Body }; using (var smtpClient = new SmtpClient()) { smtpClient.ServerCertificateValidationCallback = (s, c, h, e) => true; await smtpClient.ConnectAsync(smtpSettings.Host, smtpSettings.Port, SecureSocketOptions.Auto); smtpClient.AuthenticationMechanisms.Remove("XOAUTH2"); await smtpClient.AuthenticateAsync(smtpSettings.Username, smtpSettings.Password); await smtpClient.SendAsync(message); await smtpClient.DisconnectAsync(true); } }
public void Run() { try { List <HarperLINQ.Referral> referrals = Referral.GetNeedsReminderList(); foreach (Referral referral in referrals) { tbl_Customer member = new tbl_Customer(referral.memberid, false); string cc = null; if (referral.ccmember) { cc = member.cusEmail; } ReferralOffer offer = new ReferralOffer(referral.keycode, referral.pubcode); string membername = string.Format("{0} {1}", member.cusFirstName, member.cusLastName); string link = string.Format("{0}/Referral/Redeem.aspx?ReferralId={1}", ConfigurationManager.AppSettings["server"], System.Web.HttpUtility.UrlEncode(HarperCRYPTO.Cryptography.EncryptData(referral.id.ToString()))); string emailbody = offer.reminderemailcopy.Replace("[membername]", membername).Replace("[friendname]", referral.friendname).Replace("[link]", link); SimpleMail reminder = new SimpleMail(offer.reminderemailsubject, offer.reminderemailfromaddress, referral.friendemail, //"*****@*****.**", string.Empty, //do not cc the reminders? offer.reminderemailbcc, emailbody, offer.reminderemailishtml.HasValue ? offer.reminderemailishtml.Value : true, offer.reminderemailsmtp); reminder.Save(); referral.reminderemailid = reminder.id; referral.Save(); } } catch (Exception ex) { string SourceName = "ReferralReminder"; if (!EventLog.SourceExists(SourceName)) { EventLog.CreateEventSource(SourceName, "Application"); } EventLog eventLog = new EventLog(); eventLog.Source = SourceName; string message = string.Format("Exception: {0} \n\nStack: {1}", ex.Message, ex.StackTrace); eventLog.WriteEntry(message, EventLogEntryType.Error); } }
public Task SendMessage(SimpleMail simpleMail) { return(Task.CompletedTask); }