private SendMailAsync ( |
||
message | ||
return | System.Threading.Tasks.Task |
public async System.Threading.Tasks.Task<ActionResult> Contact(Email model) { ViewBag.Message = "Nice too meet you!"; if (ModelState.IsValid) { var body = ""; if (!string.IsNullOrEmpty(model.AboutProduct)) body = "<h2>Email From: {0} ({1})</h2></br><p>Message concerning {2}:</p><p>{3}</p>"; else body = "<h2>Email From: {0} ({1})</h2></br><p>Message:</p><p>{3}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); message.From = new MailAddress("*****@*****.**"); message.Subject = "Your email subject"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.AboutProduct, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("/Sent"); } } return View(model); }
/* * public async Task SendEmailAsync(string email, string subject, string body, bool isHtml = false) * { * var message = new MimeMessage(); * * string mailFrom = "*****@*****.**"; * * message.From.Add(new MailboxAddress(mailFrom)); * message.To.Add(new MailboxAddress(email)); * message.Subject = subject; * * var textFormat = isHtml ? TextFormat.Html : TextFormat.Plain; * message.Body = new TextPart(textFormat) * { * Text = body * }; * * using (var client = new System.Net.Mail.SmtpClient(new ProtocolLogger("smtp.log"))) * { * // Accept all SSL certificates (in case the server supports STARTTLS) * client.ServerCertificateValidationCallback = (s, c, h, e) => true; * await client.ConnectAsync(_emailConfig.SmtpServer, _emailConfig.SmtpPort, SecureSocketOptions.Auto); * * // Note: since we don't have an OAuth2 token, disable * // the XOAUTH2 authentication mechanism. * client.AuthenticationMechanisms.Remove("XOAUTH2"); * * // Note: only needed if the SMTP server requires authentication * //await client.AuthenticateAsync(_emailConfig.SmtpUsername, _emailConfig.SmtpPassword); * var netwokCredential = new System.Net.NetworkCredential(_emailConfig.SmtpUsername, _emailConfig.SmtpPassword, "ST"); * var ntlmCredential = new SaslMechanismNtlm(netwokCredential); * * await client.AuthenticateAsync(ntlmCredential); * * await client.SendAsync(message); * await client.DisconnectAsync(true); * } * } */ public async Task SendEmailAsync(string email, string subject, string body, bool isHtml = false) { MailMessage mailMessage = new MailMessage(); string str = isHtml ? "text/html; " : "text/plain; "; str = string.Concat(str, "charset=", "utf-8"); AlternateView alternateView = AlternateView.CreateAlternateViewFromString(body, new System.Net.Mime.ContentType(str)); mailMessage.AlternateViews.Add(alternateView); mailMessage.BodyEncoding = System.Text.Encoding.UTF8; mailMessage.Subject = subject; mailMessage.SubjectEncoding = System.Text.Encoding.UTF8; mailMessage.IsBodyHtml = isHtml; mailMessage.From = new MailAddress("*****@*****.**"); //mailMessage.Sender = new MailAddress("*****@*****.**"); mailMessage.To.Add(new MailAddress(email)); SmtpClient smtpClient = new System.Net.Mail.SmtpClient(_emailConfig.SmtpServer /*, _emailConfig.SmtpPort*/) { UseDefaultCredentials = false }; smtpClient.Credentials = new NetworkCredential(_emailConfig.SmtpUsername, _emailConfig.SmtpPassword, "ST"); await smtpClient.SendMailAsync(mailMessage); }
// send email via smtp service private async Task configSMTPasync(IdentityMessage message) { // Plug in your email service here to send an email. var credentialUserName = "******"; var sentFrom = "*****@*****.**"; var pwd = "123456"; // Create the message: var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination); mail.IsBodyHtml = true; mail.Subject = message.Subject; mail.Body = message.Body; // Creatte the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); // Configure the client System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("mail.tolgrup.com"); client.Port = 587; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.EnableSsl = false; client.Credentials = credentials; await client.SendMailAsync(mail); }
public async Task SendAsync(IdentityMessage message) { // Plug in your email service here to send an email. var credentialUserName = "******"; var password = "******"; // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient() { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(credentialUserName, password) }; // Create the message: try { var mail = new System.Net.Mail.MailMessage("*****@*****.**", message.Destination) { Subject = message.Subject, IsBodyHtml = true, Priority = MailPriority.High, Body = message.Body }; await client.SendMailAsync(mail); } catch (Exception ex) { throw; } }
public async Task SendEmailAsync(string destination, string customerName, string htmlMessage) { //var mineMessage = new MimeMessage(); //mineMessage.From.Add(new MailboxAddress(Email.Name,Email.EmailAddress)); //mineMessage.To.Add(new MailboxAddress(customerName,destination)); //mineMessage.Subject = Email.EmailConfirmation; //mineMessage.Body = new TextPart(TextFormat.Html) { Text = htmlMessage }; //// send email //using var smtp = new SmtpClient(); //await smtp.ConnectAsync("smtp.gmail.com", 465, SecureSocketOptions.StartTls); //await smtp.AuthenticateAsync(Email.EmailAddress, Email.Password); //await smtp.SendAsync(mineMessage); //await smtp.DisconnectAsync(true); using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**"); mail.To.Add(destination); mail.Subject = "Spice Shop"; mail.Body = htmlMessage; mail.IsBodyHtml = true; using System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587); smtp.Credentials = new NetworkCredential("*****@*****.**", "hoaibao0806^^"); smtp.EnableSsl = true; await smtp.SendMailAsync(mail); } }
public Task SendAsync(IdentityMessage message) { string emailhost = Helper.GetAppSettingAsString("emailhost"); int emailport = Convert.ToInt16(Helper.GetAppSettingAsString("emailport")); string emailFrom = Helper.GetAppSettingAsString("emailFrom"); string emailuserName = Helper.GetAppSettingAsString("emailuserName"); string emailpassword = Helper.GetAppSettingAsString("emailpassword"); bool emailenableSsl = Convert.ToBoolean(Helper.GetAppSettingAsString("emailenableSsl")); // Configure the client: var client = new System.Net.Mail.SmtpClient() { Host = emailhost, Port = emailport, EnableSsl = emailenableSsl, Credentials = new System.Net.NetworkCredential(emailuserName, emailpassword) }; MailAddress fromAddress = new MailAddress(emailFrom); // Create the message: var mail = new System.Net.Mail.MailMessage(); mail.From = fromAddress; mail.To.Add(message.Destination); mail.Subject = message.Subject.Replace('\r', ' ').Replace('\n', ' '); mail.Body = message.Body; mail.IsBodyHtml = true; return(client.SendMailAsync(mail)); }
// send email via smtp service private async Task configSMTPasync(IdentityMessage message) { // Plug in your email service here to send an email. var credentialUserName = ReadSetting("KVL.Portal.Email.User"); var sentFrom = message.Destination; var pwd = ReadSetting("KVL.Portal.Email.Password"); // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); //System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Port = Convert.ToInt16(ReadSetting("KVL.Portal.Email.Port")); client.Host = ReadSetting("KVL.Portal.Email.Host"); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = Convert.ToBoolean(ReadSetting("KVL.Portal.Email.UseDefaultCredentials")); // Creatte the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = Convert.ToBoolean(ReadSetting("KVL.Portal.Email.HttpsEnabled")); client.Credentials = credentials; // Create the message: var mail = new MailMessage(sentFrom, message.Destination); mail.From = new MailAddress(credentialUserName); mail.Subject = message.Subject; mail.Body = message.Body; mail.IsBodyHtml = Convert.ToBoolean(ReadSetting("KVL.Portal.Email.IsBodyHtml")); await client.SendMailAsync(mail); }
public static async Task<bool> SendMailWelcome(string toEmail, object data) { try { var client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; var welcomeMail = ConfigurationManager.AppSettings["GOPLAY_WELCOME_EMAIL_SENDER"]; var displayName = ConfigurationManager.AppSettings["GOPLAY_WELCOME_EMAIL_NAME"]; var from = new MailAddress(welcomeMail, displayName); var to = new MailAddress(toEmail); var mailMessage = new MailMessage(from, to) { Subject = "Thank you for signing up!", Body = GetEmailBody(ConfigurationManager.AppSettings["WelcomeMessageTemplate"], data), IsBodyHtml = true }; await client.SendMailAsync(mailMessage); return true; } catch { return false; } }
public async Task<ActionResult> Index(User model) { if (ModelState.IsValid) { var randomNumber = ActivationCode(); var body = "<p>Dear Customer,</p><p>This is the activation code that has been sent to you in order to validate your registration on BontoBuy</p><p>Your activation code: {0}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress(model.Email)); //The mail of the person registering on the website message.From = new MailAddress("*****@*****.**"); message.Subject = "Register on BontoBuy"; message.Body = string.Format(body, randomNumber); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent", "Home"); } } return View(model); }
public async Task<ActionResult> Contact(EmailFormModel model, string toEmail) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); toEmail = model.ToEmail; //message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.To.Add(toEmail); message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "Your email subject"; message.Body = string.Format(body, model.FromName, model.FromEmail,model.ToEmail, model.Message); message.IsBodyHtml = true; if (model.Upload != null && model.Upload.ContentLength > 0) { message.Attachments.Add(new Attachment(model.Upload.InputStream, Path.GetFileName(model.Upload.FileName))); } using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp-mail.outlook.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
public async static Task<string> SendMailReminder(EmailFormModel model) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "Your email subject"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return "conplete"; } }
private async Task SendMail(string email, string subject, string body) { var credentialUserName = "******"; var sentFrom = "beteuro.com.pl"; var pwd = "para$OLKA17"; MailAddress from = new MailAddress(credentialUserName, sentFrom); MailAddress to = new MailAddress(email); // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com"); client.Port = 587; client.EnableSsl = true; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Creatte the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = true; client.Credentials = credentials; // Create the message: var mail = new System.Net.Mail.MailMessage(from, to); mail.Subject = subject; mail.Body = body; // Send: await client.SendMailAsync(mail); }
// public async Task SendEmailSync(string email, string subject, string body) // { //try //{ // var message = new MimeMessage(); // message.From.Add(new MailboxAddress(_smtp.SenderName, _smtp.SenderEmail)); // message.To.Add(new MailboxAddress(_smtp.SenderName, email)); // message.Subject = subject; // message.Body = new TextPart("html") // { // Text = body // }; // using (var client = new SmtpClient()) // { // client.ServerCertificateValidationCallback += (s, c, h, e) => true; // client.CheckCertificateRevocation = false; // if (_env.IsDevelopment()) // await client.ConnectAsync(_smtp.Server, _smtp.Port, true); // else // await client.ConnectAsync(_smtp.Server); // await client.AuthenticateAsync(_smtp.SenderEmail, _smtp.Password); // await client.SendAsync(message); // await client.DisconnectAsync(true); // } //} //catch (Exception e) //{ // throw new InvalidOperationException(e.Message); //} // } // email, tiêu đề, nội dung public async Task <string> SendEmailSync(string email, string subject, string body) { try { using (MailMessage message = new MailMessage()) { message.From = new MailAddress(_smtp.Username, _smtp.SenderName); message.To.Add(email); message.Subject = subject; message.SubjectEncoding = Encoding.UTF8; message.Body = body; message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; using (SmtpClient smtpClient = new SmtpClient(_smtp.Server, _smtp.Port)) { smtpClient.Credentials = (ICredentialsByHost) new NetworkCredential(_smtp.Username, _smtp.Password); smtpClient.EnableSsl = true; await smtpClient.SendMailAsync(message); } return("Send Successfull"); } } catch (Exception ex) { return(ex.Message); } }
public Task SendEmailAsync(string to, string subject, string message, string bcc = null) { // Configure the client: SmtpClient client = new System.Net.Mail.SmtpClient(EmailSettings.Server); client.Port = EmailSettings.Port; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Create the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential( EmailSettings.UserName, EmailSettings.Password); client.EnableSsl = EmailSettings.EnableSsl; client.Credentials = credentials; // Create the message: var mail = new System.Net.Mail.MailMessage( new MailAddress(EmailSettings.UserName, EmailSettings.DisplayName), new MailAddress(to, to)); if (!string.IsNullOrEmpty(bcc)) { mail.Bcc.Add(new MailAddress(bcc)); } mail.Subject = subject; mail.IsBodyHtml = true; mail.Body = message; // Send: return(client.SendMailAsync(mail)); }
// send email via smtp service private async Task configSMTPasync(IdentityMessage message) { // Plug in your email service here to send an email. var credentialUserName = "******"; var sentFrom = "*****@*****.**"; var pwd = "TrangNgo"; var fromName = "DoAnIII"; // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com"); client.Port = 587; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Creatte the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = true; client.Credentials = credentials; client.Timeout = 100000; // Create the message: var mail = new System.Net.Mail.MailMessage(); mail.To.Add(new MailAddress(message.Destination)); mail.Subject = message.Subject; mail.Body = message.Body; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.IsBodyHtml = true; mail.From = new MailAddress(sentFrom, fromName); mail.Priority = MailPriority.High; await client.SendMailAsync(mail); }
public async Task SendEmail(Email emailContent) { using (var emailMessage = new MailMessage { From = new MailAddress("*****@*****.**") }) { emailMessage.To.Add(new MailAddress(emailContent.EmailAdress)); emailMessage.Subject = emailContent.Subject; emailMessage.Body = emailContent.TextBody; emailMessage.IsBodyHtml = true; using (var client = new SmtpClient()) { var credentials = new NetworkCredential { UserName = "******", Password = "******" }; client.Host = "smtp.gmail.com"; client.Port = 587; client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = credentials; client.DeliveryMethod = SmtpDeliveryMethod.Network; await client.SendMailAsync(emailMessage); } } }
public async Task SendEmail(string smtpFrom,string smtpTo, string messageSubject, string messageBody) { int smtpPort = int.Parse(ConfigurationManager.AppSettings["SMTP_Port"]); string smtpServer = ConfigurationManager.AppSettings["SMTP_Server"]; //string smtpTo = ConfigurationManager.AppSettings["SMTP_To"]; string smtpUser = ConfigurationManager.AppSettings["SMTP_User"]; string smtpPassword = ConfigurationManager.AppSettings["SMTP_Password"]; bool smtpUseSSL = ConfigurationManager.AppSettings["SMTP_UseSSL"] == "1"; MailMessage mail = new MailMessage(smtpFrom, smtpTo); mail.Headers.Add("From", smtpFrom); SmtpClient client = new SmtpClient(); client.Port = smtpPort; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = smtpServer; client.EnableSsl = smtpUseSSL; if(!string.IsNullOrWhiteSpace(smtpPassword)) client.Credentials = new System.Net.NetworkCredential(smtpUser, smtpPassword); client.Timeout = 20000; mail.Subject = messageSubject; mail.Body = messageBody; mail.IsBodyHtml = true; await client.SendMailAsync(mail); }
public async Task Send(BaseMessage msg) { var data = (EMailMessage)msg; using (var client = new System.Net.Mail.SmtpClient()) { client.SendCompleted += client_SendCompleted; var mail = new MailMessage(); mail.Subject = data.Subject; mail.Body = data.Ctx; mail.IsBodyHtml = true; var receivers = data.Receiver.ToMailAddress(); foreach (var r in receivers) { mail.To.Add(r); } await client.SendMailAsync(mail, msg) .ContinueWith(t => { t.Exception.Handle(ex => { return(true);//如果不加这一句,发邮件异常的时候,会直接关闭程序。 }); }, TaskContinuationOptions.OnlyOnFaulted) .ContinueWith(t => { //为毛会到这里? var ex = t.Exception; }, TaskContinuationOptions.OnlyOnCanceled); } }
public Task SendAsync(IdentityMessage message) { // настройка логина, пароля отправителя const string @from = "*****@*****.**"; const string pass = "******"; // адрес и порт smtp-сервера, с которого мы и будем отправлять письмо var client = new SmtpClient("smtp.gmail.com", 587) { DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential(@from, pass), EnableSsl = true }; // создаем письмо: message.Destination - адрес получателя var mail = new MailMessage(from, message.Destination) { Subject = message.Subject, Body = message.Body, IsBodyHtml = true }; return client.SendMailAsync(mail); }
private async void btnSend_Click(object sender, RoutedEventArgs e){ try { _sendingReport = true; IsHitTestVisible = false; lblInfo.Visibility = Visibility.Visible; lblInfo.Text = "Sending Report..."; var from = new MailAddress("*****@*****.**", "PCSX2 Tester"); var to = new MailAddress("*****@*****.**", "PCSX2 Developer"); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 0x24b, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(from.Address, "h@te3027"), Timeout = 0x4e20 }; var asyncVariable0 = new MailMessage(from, to) { Subject = "Error Report", Body = Message + "\n\n\n" + StackTrace }; using (var message = asyncVariable0) { await smtp.SendMailAsync(message); } _sendingReport = false; lblInfo.Text = "Report Sent!"; await Task.Delay(0x3e8); Environment.Exit(0); } catch { Environment.Exit(0); } }
public async Task SendEmailAsync(string recipient, string subject, string message) { // Configure the client: SmtpClient client = new System.Net.Mail.SmtpClient("smtp-mail.outlook.com"); client.Port = 587; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Create the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(_sender, _password); client.EnableSsl = true; client.Credentials = credentials; // Create the message: var mail = new MailMessage(_sender.Trim(), recipient.Trim()); mail.Subject = subject; mail.Body = message; // Send: await client.SendMailAsync(mail); }
/// <summary> /// Email method to send emails to the /// designated person(s) using the /// Gmail settings we have in the Web.Config /// Class is private as only the SendAsync /// method needs to call/use it /// </summary> /// <param name="message"></param> /// <returns></returns> private Task configSendEmailasync(IdentityMessage message) { var email = new MailMessage(); //formatting the email to be sent email.To.Add(message.Destination); email.From = new System.Net.Mail.MailAddress("*****@*****.**", "Revature"); email.Subject = message.Subject; email.Body = message.Body; email.IsBodyHtml = true; //smtp settings that we pull //from the app.config file System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient { Host = ConfigurationManager.AppSettings["GmailHost"], Port = Int32.Parse(ConfigurationManager.AppSettings["GmailPort"]), EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(ConfigurationManager.AppSettings["GmailUserName"], ConfigurationManager.AppSettings["GmailPassword"]) }; //sends the email return(Task.Run(() => smtp.SendMailAsync(email))); }
public async Task<ActionResult> Submit(Email email) { if (ModelState.IsValid) { db.Emails.Add(email); db.SaveChanges(); var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.From = new MailAddress(email.Email1); // replace with valid value message.Subject = "Your email subject"; message.Body = string.Format(body, email.Name, email.Email1, email.Request); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", //sender's username Password = "******" // sender's Password }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Index"); } } return View(); }
//[HttpPost] //[ValidateAntiForgeryToken] public async Task<ActionResult> Contact(EmailFormModel model) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress(model.ToEmail)); message.From = new MailAddress(model.FromEmail); message.Subject = "test"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; message.Attachments.Add(new Attachment(model.File.InputStream, Path.GetFileName(model.File.FileName))); using (SmtpClient smtp = new SmtpClient()) { NetworkCredential credetial = new NetworkCredential { UserName = model.FromEmail, Password = model.Password }; smtp.Credentials = credetial; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
async public Task Send(string from, string to, string message) { using (var client = new SmtpClient()) { await client.SendMailAsync(from, to, "", message); } }
public async static TaskEventHandler SendEmailAsync(string email, string subject, string message) { try { var _email = "*****@*****.**"; var _epass = ConfigurationManager.AppSettings["EmailPassword"]; var _dispName = "Sean"; MailMessage myMessage = new MailMessage(); myMessage.To.Add(email); myMessage.From = new MailAddress(_email, _dispName); myMessage.Subject = subject; myMessage.Body = message; myMessage.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient()) { smtp.EnableSsl = true; smtp.Host = "smtp.live.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(_email, _epass); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.SendCompleted += (s, e) => { smtp.Dispose(); }; await smtp.SendMailAsync(myMessage); } } catch(Exception ex) { throw ex; } }
public async Task EmailSendAsync(MessageModel messageModel) { using (MailMessage mailMessage = new MailMessage()) { mailMessage.From = new MailAddress(_configuration.GetSection("EmailConfiguration").GetSection("FromEmail").Value.ToString(), _configuration.GetSection("EmailConfiguration").GetSection("FromName").Value.ToString(), Encoding.UTF8); mailMessage.Subject = messageModel.Subject; mailMessage.SubjectEncoding = Encoding.UTF8; mailMessage.Body = messageModel.Content; mailMessage.BodyEncoding = Encoding.UTF8; mailMessage.IsBodyHtml = true; mailMessage.BodyTransferEncoding = TransferEncoding.Base64; mailMessage.To.Add(new MailAddress(messageModel.To)); NetworkCredential networkCredential = new NetworkCredential(_configuration.GetSection("EmailConfiguration").GetSection("Username").Value.ToString(), _configuration.GetSection("EmailConfiguration").GetSection("Password").Value.ToString()); System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); smtpClient.Host = _configuration.GetSection("EmailConfiguration").GetSection("SmtpServer").Value.ToString(); smtpClient.EnableSsl = Convert.ToBoolean(_configuration.GetSection("EmailConfiguration").GetSection("SSL").Value); smtpClient.UseDefaultCredentials = Convert.ToBoolean(_configuration.GetSection("EmailConfiguration").GetSection("UseDefaultCredentials").Value); smtpClient.Port = Convert.ToInt32(_configuration.GetSection("EmailConfiguration").GetSection("Port").Value); smtpClient.Credentials = networkCredential; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; await smtpClient.SendMailAsync(mailMessage); smtpClient.Dispose(); } }
/// <summary> /// Sends an email /// </summary> /// <param name="subject"></param> /// <param name="body"></param> /// <param name="to"></param> /// <returns></returns> public static Task SendAsync(string subject, string body, string to) { // Credentials var credentialUserName = ConfigurationManager.AppSettings["SmtpUserName"]; var sentFrom = ConfigurationManager.AppSettings["SmtpSendFrom"]; var pwd = ConfigurationManager.AppSettings["SmtpPassword"]; var server = ConfigurationManager.AppSettings["SmtpHostName"]; var port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]); // Configure the client var client = new SmtpClient(server); client.Port = port; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.EnableSsl = false; // Create the credentials client.Credentials = new NetworkCredential(credentialUserName, pwd); // Create the message var mail = new MailMessage(sentFrom, to); mail.IsBodyHtml = true; mail.Subject = subject; mail.Body = body; // Send return client.SendMailAsync(mail); }
public static async Task <bool> SendMailWithoutCalendarInvite(EmailTemplate emailTemplate) { if (emailTemplate != null && emailTemplate.ToEmailAddress.Length > 0) { LoadEmailSettings(ref emailTemplate); System.Net.Mail.MailMessage msg = new MailMessage(); foreach (string recepient in emailTemplate.ToEmailAddress) { msg.To.Add(recepient); } msg.From = new MailAddress(emailTemplate.EmailFromAddress, emailTemplate.EmailFromDisplayName); msg.Body = emailTemplate.Body; msg.Subject = emailTemplate.Subject; try { System.Net.Mail.SmtpClient smtpclient = new System.Net.Mail.SmtpClient(); smtpclient.Host = emailTemplate.Host; smtpclient.Port = emailTemplate.Port; smtpclient.EnableSsl = emailTemplate.EnableSsl; smtpclient.Credentials = new System.Net.NetworkCredential(emailTemplate.EmailFromAddress, emailTemplate.EmailFromPassword); await smtpclient.SendMailAsync(msg); return(true); } catch (System.Exception ex) { return(false); } } return(false); }
public async Task sendEMailAsync(string email, string subject, string htmlMessage) { var message = new MailMessage() { From = new MailAddress("*****@*****.**", "IT Akademija"), }; message.To.Add(new MailAddress(email, email)); message.Subject = subject; message.Body = htmlMessage; message.IsBodyHtml = true; message.Priority = MailPriority.High; try { using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)) { client.Credentials = new NetworkCredential("*****@*****.**", "Mostar2019"); client.EnableSsl = true; await client.SendMailAsync(message); } } catch (Exception e) { Console.WriteLine("Send Mail Failed : " + e.Message); } }
public async Task<ActionResult> Index(ContactViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Gelieve alles correct in te vullen."); return View(model); } else { //Als bericht verzonden wordt -> var body = "<html><body style='color:grey; font-size:15px;'>" + "<font face='Helvetica, Arial, sans-serif'>" + "<h1>U heeft een nieuw bericht</h1><br/>" + "<div style='background-color: #DDDDDD;border:1px solid black;padding: 1%;'><p> <strong>DATUM:</strong> {3} </p>" + "<p> <strong>NAAM:</strong> {0} {1} </p>" + "<p> <strong>EMAIL:</strong> {2} </p>" + "<p> <strong>TEL. NUMMER:</strong> {4} </p><br/>" + " <p> <strong>BERICHT:</strong> </p><p> {5} </p>" + "</div></body></html>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); //replace with valid value message.Subject = "GULSERVICES WEBMAIL | " +model.Voornaam + " " + model.Achternaam; message.Body = string.Format(body, model.Achternaam, model.Voornaam, model.Email, DateTime.Now, model.Telefoonnummer, model.Bericht); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { await smtp.SendMailAsync(message); return RedirectToAction("Verzonden"); } } }
public async Task<ActionResult> Message(string mail, string konu, string ileti) { var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "Your email subject"; message.Body = ileti; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Index", "Home"); } return RedirectToAction("Index", "Home"); }
public void NewVendorRegistrationNotification(string email, string address) { MailMessage mail = new MailMessage(); SmtpClient client = new SmtpClient(); client.Port = 25; client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; //client.UseDefaultCredentials = false; client.Host = "email-smtp.us-east-1.amazonaws.com"; //mail.To.Add(new MailAddress(to)); mail.To.Add("*****@*****.**"); mail.To.Add("*****@*****.**"); //mail.To.Add("*****@*****.**"); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Parko - New vendor registration"; mail.IsBodyHtml = true; var param = new string[] { email, address}; mail.Body = GetMessage(param, System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplates/NewVendorRegistration.html")); //client.UseDefaultCredentials = true; client.Credentials = new NetworkCredential("AKIAIYETBGWCLSE6K4QQ", "ApQQr4uByzNo5xfvftiVZbTUUfTwtirxJdB9jWKBIE+J"); var userToken = "something"; //client.Send(mail); client.SendMailAsync(mail); }
public async Task<ActionResult> Contact(FormCollection body) { var from = String.IsNullOrEmpty(body["Email"]) ? "*****@*****.**" : body["Email"]; var comments = body["Comments"]; var content = string.Format("<p>Email From: {0}</p><p>Message:</p><p>{1}</p>", from, comments); var message = new MailMessage(); message.From = new MailAddress("*****@*****.**"); // "*****@*****.**"; replace with valid value message.To.Add(new MailAddress("*****@*****.**")); // "*****@*****.**"; replace with valid value message.Subject = "Email from my .NET portfolio site!"; message.Body = content; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // "*****@*****.**"; replace with valid value Password = "******" // "Password"; replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("ContactThanks"); } }
public Task SendAsync(IdentityMessage message) { // Credentials: var credentialUserName = ConfigurationManager.AppSettings["SendGrid_UserName"]; var sentFrom = "*****@*****.**"; var sendGridPassword = ConfigurationManager.AppSettings["SendGrid_Password"]; // Configure the client: var client = new System.Net.Mail.SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587)); client.Port = 587; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Create the credentials: NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, sendGridPassword); client.EnableSsl = true; client.Credentials = credentials; string text = string.Format("Please click on this link to {0}: {1}", message.Subject, message.Body); string html = "Please confirm your account by clicking this link: <a href=\"" + message.Body + "\">link</a><br/>"; html += HttpUtility.HtmlEncode(@"Or click to copy the following link in the browser:" + message.Body); var mail = new MailMessage(sentFrom, message.Destination) { Subject = message.Subject, Body = message.Body }; // Send: return(client.SendMailAsync(mail)); }
//Method sends the email private async Task<String> SendEmail(string name, string email, string messages, string phone, int Id) { var getRecordEmployee = db.Records.First(i => i.Id == Id).Record_Employee; var getEmployeeEmail = db.Employees.First(i => i.Id == getRecordEmployee).UserName; var getEmployeeName = db.Employees.First(i => i.Id == getRecordEmployee).FirstName; var message = new MailMessage(); message.To.Add(new MailAddress(getEmployeeEmail)); // replace with receiver's email id message.From = new MailAddress("*****@*****.**"); // replace with sender's email id message.Subject = "EPMS Email Notification"; message.Body = messages; message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // sender's email id Password = "******" // Sender password }; smtp.Credentials = credential; smtp.Host = "smtp.live.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return "sent"; } }
public async Task<ActionResult> Contact(EmailFormModel model) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); message.From = new MailAddress(model.FromEmail); message.Subject = model.Subject; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtpClient = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", Password = "******" }; smtpClient.Credentials = credential; //was getting error fixed with smtpClient.Host = "smtp.gmail.com"; //security settings at the followig link https://www.google.com/settings/security/lesssecureapps and enable less secure apps smtpClient.Port = 587; smtpClient.EnableSsl = true; await smtpClient.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
private async Task ConfigAndSendMessage(IdentityMessage message) { _smtpServer = "msex1.office.finam.ru"; _from = "*****@*****.**"; try { var email = new MailMessage(new MailAddress(_from), new MailAddress(message.Destination)) { Subject = message.Subject, Body = message.Body, IsBodyHtml = true }; using (var client = new SmtpClient()) { client.Host = _smtpServer; client.Port = 25; client.Credentials = new NetworkCredential("*****@*****.**", "UfrRJzmuR89k"); // client.UseDefaultCredentials = true; await client.SendMailAsync(email); } } catch (Exception ex) { Console.WriteLine("Send message error", ex.ToString()); } }
public async Task<ActionResult> Contact(Email model) { if (ModelState.IsValid) { var body = "<p>Petición de Contacto de: {0} ({1})</p></br></br></br><p>Mensaje:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // a quien se lo envia tomarlo desde la propiedad enviar q copia el propiertario y al interesado message.From = new MailAddress("*****@*****.**"); // quien lo envia message.Subject = "Peticion de Contacto: "+model.FromName; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
//public void ReadImap() //{ // List<MailServer_m> li = SMTP_List(); // var mailRepository = new MailRepository( // li[0].mailserver, // li[0].port, // li[0].ssl, // li[0].Login, // "3hgb8wy3hgb8wy" // ); // var emailList = mailRepository.GetUnreadMails("inbox"); // foreach (Message email in emailList) // { // if (email.From.Email.ToString() == "*****@*****.**") // { // MessageBox.Show("siker"); // } // } //} public void sendMail(string to, string email_body) { List <MailServer_m> li = SMTP_List(); try { MailMessage mail = new MailMessage(); System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient(li[0].mailserver); SmtpServer.Port = li[0].port; SmtpServer.Credentials = new System.Net.NetworkCredential(li[0].login, "pmhr2018"); SmtpServer.EnableSsl = true; mail.From = new MailAddress(li[0].login); mail.To.Add(to); mail.Subject = "HR Portal - Phoenix Mecano Kecskemét kft."; mail.Body = email_body; mail.IsBodyHtml = true; SmtpServer.SendMailAsync(mail); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public async Task SendAsync(IdentityMessage message) { try { MailMessage mail = new MailMessage(); mail.To.Add(message.Destination); mail.From = new MailAddress("*****@*****.**","SEATS"); mail.Subject = message.Subject; mail.Body = message.Body; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient()) { smtp.Host = "198.60.12.9"; smtp.Port = 25; //smtp.UseDefaultCredentials = true; await smtp.SendMailAsync(mail); } mail.Dispose(); } catch (Exception ex) { throw new HttpException(500, "Confirmation Email Not Sent! " + ex.Message); } }
public async Task<ActionResult> Contact(OTMST.Models.MVCEmail model) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.To.Add(new MailAddress("*****@*****.**")); message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "OTMST inquiry from web"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient("localhost")) { //var credential = new NetworkCredential //{ // UserName = "******", // replace with valid value // Password = "******" // replace with valid value //}; //smtp.Credentials = credential; //smtp.Host = "smtp-mail.outlook.com"; //smtp.Port = 587; //smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
public async Task <bool> SendEmail(string asunto, string contenido, NotificationMetadata notificationMetadata) { try{ MailMessage mm = new MailMessage(notificationMetadata.Sender, notificationMetadata.Reciever, asunto, contenido); System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587) { EnableSsl = true, Credentials = new NetworkCredential(notificationMetadata.Sender, notificationMetadata.Password) }; await client.SendMailAsync(mm); //EmailMessage message = new EmailMessage(); //message.Sender = new MailboxAddress(notificationMetadata.Sender); //message.Reciever = new MailboxAddress(notificationMetadata.Reciever); //message.Subject = asunto; //message.Content = contenido; //var mimeMessage = CreateMimeMessageFromEmailMessage(message); //using (SmtpClient smtpClient = new SmtpClient()) //{ // await smtpClient.ConnectAsync(notificationMetadata.SmtpServer, notificationMetadata.Port, true); // await smtpClient.AuthenticateAsync(notificationMetadata.UserName, notificationMetadata.Password); // await smtpClient.SendAsync(mimeMessage); // await smtpClient.DisconnectAsync(true); //} return(true); } catch (Exception ex) { throw ex; } }
public Task SendAsync(IdentityMessage message) { Debug.WriteLine("aawhndl;kuajwhbdlaw: 8"); // Credentials: var credentialUserName = "******"; var sentFrom = "*****@*****.**"; var pwd = "gogreengo"; // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com"); client.Port = 587; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Create the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = true; client.Credentials = credentials; // Create the message: // TODO: change "*****@*****.**" to message.Destination in production var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination); mail.Subject = message.Subject; mail.Body = message.Body; // Send: return(client.SendMailAsync(mail)); }
// send email via smtp service private async Task configSMTPasync(IdentityMessage message) { // Plug in your email service here to send an email. var credentialUserName = "******"; var sentFrom = "*****@*****.**"; var pwd = "ourpassword"; // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("mail.ourdomain.com"); client.Port = 25; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Creatte the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = false; client.Credentials = credentials; // Create the message: var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination); mail.Subject = message.Subject; mail.Body = message.Body; await client.SendMailAsync(mail); }
/// <summary> /// /// </summary> /// <param name="smtpClient"></param> /// <param name="MailFrom_Address"></param> /// <param name="MailTo_Address"></param> /// <param name="Subject"></param> /// <param name="Body"></param> /// <param name="IsBodyEncoded"></param> /// <param name="IsBodyHtml"></param> /// <param name="Priority"></param> /// <param name="Attachments">DisposableList<Attachment></param> /// <returns></returns> public static async Task InviaEmailAsync(SmtpClient smtpClient, MailAddress MailFrom_Address, string MailsTo, string Subject, string Body, bool IsBodyEncoded = false, bool IsBodyHtml = false, MailPriority Priority = MailPriority.Normal, List<Attachment> Attachments = null) { using (MailMessage mailMsg = new MailMessage()) { mailMsg.From = MailFrom_Address; mailMsg.To.Add(MailsTo); mailMsg.Subject = Subject; string body = Body; if (IsBodyEncoded) body = System.Net.WebUtility.HtmlDecode(body); mailMsg.Body = body; mailMsg.IsBodyHtml = IsBodyHtml; mailMsg.Priority = Priority; //allegati if (Attachments != null && Attachments.Count > 0) foreach (var attach in Attachments) mailMsg.Attachments.Add(attach); await smtpClient.SendMailAsync(mailMsg).ConfigureAwait(false); } }
private async Task SendMailAsync(EmailMessage message) { var client = new SmtpClient { Host = Host, Timeout = Timeout, Port = PortNumber, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(MailAccount, Password) }; var mail = new MailMessage(); mail.To.Add(new MailAddress(message.Destination)); mail.From = new MailAddress(SendAddress, DisplayName); mail.Subject = message.Subject; mail.Body = message.Body; mail.BodyEncoding = Encoding.UTF8; try { await client.SendMailAsync(mail); } catch (Exception ex) { Trace.TraceError(ex.Message + " SendGrid probably not configured correctly."); } }
public void SendEmail(string[] toEmailAddresses, string subject, string body) { if(_settings.Enabled) { MailMessage message = new MailMessage(); MailAddress sender = new MailAddress(_settings.UserName, _settings.DisplayName); SmtpClient smtp = new SmtpClient() { Host = _settings.Server, Port = _settings.Port, EnableSsl = _settings.EnableSsl, UseDefaultCredentials = false, Credentials = new System.Net.NetworkCredential(_settings.UserName, _settings.Password), DeliveryMethod = SmtpDeliveryMethod.Network }; message.From = sender; foreach (var strEmail in toEmailAddresses) message.To.Add(new MailAddress(strEmail.Trim())); message.Subject = subject; message.Body = body; message.IsBodyHtml = true; //smtp.Send(message); smtp.SendMailAsync(message); } }
public async Task<ActionResult> Contact(EmailFormModel model) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "Your email subject"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp-mail.outlook.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
public static async Task<bool> SendMailResetPasword(string toEmail, object data) { try { var client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; var supportEmail = ConfigurationManager.AppSettings["HI_EMAIL_SENDER"]; var displayName = ConfigurationManager.AppSettings["HI_EMAIL_NAME"]; var from = new MailAddress(supportEmail, displayName); var to = new MailAddress(toEmail); var mailMessage = new MailMessage(from, to) { Subject = "GToken - Reset Password", Body = GetEmailBody(ConfigurationManager.AppSettings["ResetPasswordTemplate"],data), IsBodyHtml = true }; await client.SendMailAsync(mailMessage); return true; } catch { return false; } }
public async Task<ActionResult> Contact(EmailFormModel model) { if (ModelState.IsValid) { var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; var message = new MailMessage(); message.To.Add(new MailAddress("*****@*****.**")); // TO message.From = new MailAddress("*****@*****.**"); // FROM message.Subject = "Your email subject"; message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // Email Password = "******" // Pass }; smtp.Credentials = credential; smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; await smtp.SendMailAsync(message); return RedirectToAction("Sent"); } } return View(model); }
public object Post(TestNotification request) { var options = GetOptions(request.UserID); var mail = new MailMessage(options.EmailFrom, options.EmailTo) { Subject = "Emby: Test Notification", Body = "This is a test notification from MediaBrowser" }; var client = new SmtpClient { Host = options.Server, Port = options.Port, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false }; if (options.SSL) client.EnableSsl = true; if (options.UseCredentials) { var pw = _encryption.DecryptString(options.PwData); client.Credentials = new NetworkCredential(options.Username, pw); } return client.SendMailAsync(mail); }
public async Task <bool> Send(string mail, string subject, string body) { //var smtpClient = new SmtpClient //{ // Host = "smtp.gmail.com", // set your SMTP server name here // Port = 587, // Port // UseDefaultCredentials = false, // EnableSsl = true, // Credentials = new NetworkCredential("*****@*****.**", "SOLOM19895050") //}; //NetworkCredential networkCredentials = new //NetworkCredential("[email protected]", "allah1akbar"); ////NetworkCredential("*****@*****.**", "Ayman1988@"); //SmtpClient smtpClient = new SmtpClient(); //smtpClient.UseDefaultCredentials = false; //smtpClient.Credentials = networkCredentials; ////smtpClient.Host = "smtp.office365.com"; //smtpClient.Host = "smtp.gmail.com"; //smtpClient.Port = 587; //smtpClient.EnableSsl = true; var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential("*****@*****.**", "P@ss123&P@ss123"); smtp.Timeout = 20000; } //using (var message = new MailMessage("*****@*****.**", mail) using (var message = new MailMessage("*****@*****.**", mail) { Subject = subject, Body = $"<body>{body}</body>", IsBodyHtml = true }) { try { await smtp.SendMailAsync(message); } catch (Exception ex) { logger.LogInfo("Failed to send the mail"); logger.LogError(ex.ToString()); return(false); } } return(true); }
public async Task sentEmail(string filename, string locationStr, int locationIndex) { try { System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(filename, System.Net.Mime.MediaTypeNames.Text.Html); var msg = new MailMessage(); List <string> emailList = _context.LocationEmail.Where(x => x.LocationIndex == locationIndex).Select(x => x.Email).ToList(); string emailListString = ""; foreach (string email in emailList) { msg.To.Add(new MailAddress(email)); } var credentialUserName = "******"; var sentFrom = "*****@gmail.com"; var pwd = "**********"; var smtp = new System.Net.Mail.SmtpClient("****.com", 587); var creds = new System.Net.NetworkCredential(credentialUserName, pwd); smtp.UseDefaultCredentials = false; smtp.Credentials = creds; smtp.EnableSsl = false; //var to = new MailAddress(emailListString); var from = new MailAddress(sentFrom, "SkyTech Mask Monitoring System"); //msg.To.Add(to); msg.From = from; msg.IsBodyHtml = true; msg.Subject = "Notification of people without mask"; msg.Body = "Date Time: " + DateTime.Now + "<br/>"; msg.Body = msg.Body + "Location: " + locationStr + "<br/><br/>"; msg.Body = msg.Body + "A person not wearing mask is discovered in the premises.<br/> This is a system generated email. Please do not reply."; if (attachment != null) { msg.Attachments.Add(attachment); } await smtp.SendMailAsync(msg); smtp.Dispose(); } catch (Exception ex) { Debug.WriteLine("Sent Email"); Debug.WriteLine(ex.InnerException); } finally { } }
public async Task <ActionResult> Register([Bind(Include = "EmailOrPhone")] UserRegistrationViewModel registerForm) { if (ModelState.IsValid) { if (db.TBUsers.Any(r => r.FDEmailOrPhone == registerForm.EmailOrPhone)) { ModelState.AddModelError("EmailOrPhone", "Email address has been used"); } else { //db.TBUsers.Add(new TBUser { FDEmailOrPhone = registerForm.EmailOrPhone, FDNickname = " " }); //db.SaveChanges(); SqlParameter emailParameter = new SqlParameter("FDEmailOrPhone", SqlDbType.VarChar, Common.Const.EmailOrPhoneLength); emailParameter.Value = registerForm.EmailOrPhone; string verifyCode = Common.RandomGenerator.GenerateRandomString(Common.Const.VerificationCodeLength); SqlParameter passwordParameter = new SqlParameter("FDPassword", SqlDbType.VarChar, Common.Const.VerificationCodeLength); passwordParameter.Value = verifyCode; db.Database.ExecuteSqlCommand("insert into TBUsers (FDEmailOrPhone,FDNickname,FDPassword) values (@FDEmailOrPhone,' ',HASHBYTES('SHA2_256',@FDPassword))", emailParameter, passwordParameter); string body = "<h2>{0}</h2>"; var message = new MailMessage(); message.To.Add(new MailAddress(registerForm.EmailOrPhone)); // replace with valid value message.From = new MailAddress("*****@*****.**"); // replace with valid value message.Subject = "Registration Validation Code"; message.Body = String.Format(body, verifyCode); message.IsBodyHtml = true; using (var smtp = new System.Net.Mail.SmtpClient()) { var credential = new NetworkCredential { UserName = "******", // replace with valid value Password = "******" // replace with valid value }; smtp.Credentials = credential; smtp.Host = "smtp-mail.outlook.com"; smtp.Port = 587; smtp.EnableSsl = true; //smtp.Send(message); await smtp.SendMailAsync(message); //return RedirectToAction("Sent"); } Session.Add("userid", registerForm.EmailOrPhone); UserRegistrationCodeVerificationViewModel p = new UserRegistrationCodeVerificationViewModel(); p.EmailOrPhone = Session["userid"].ToString(); return(View("RegistrationCodeVerification", p)); } } return(View(registerForm)); }
public Task SendEmailAsync(MailMessage mailMessage) { System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(host: Host, port: Port) { EnableSsl = Ssl, Credentials = new NetworkCredential(Email, Password), }; mailMessage.From = new MailAddress(Email, "NorthOps"); return(client.SendMailAsync(message: mailMessage)); }
public Task SendAsync(IdentityMessage message) { // Plug in your email service here to send an email. //return Task.FromResult(0); // Credentials: var credentialUserName = "******"; var sentFrom = "*****@*****.**"; var pwd = "abcdefg"; // Configure the client: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //("mail.hawaii.edu"); client.Port = 587; //25; client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; // Create the credentials: System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(credentialUserName, pwd); client.EnableSsl = true; client.Credentials = credentials; // Create the message: var mail = new System.Net.Mail.MailMessage(sentFrom, message.Destination); mail.Subject = message.Subject; mail.Body = message.Body; mail.IsBodyHtml = true; //trackingEmail string trackingEmail = System.Configuration.ConfigurationManager.AppSettings["trackingEmail"]; MailAddress replyTo = new MailAddress(trackingEmail); if (!String.Equals(message.Destination, replyTo.Address, StringComparison.OrdinalIgnoreCase)) { //string superAdminEmail = System.Configuration.ConfigurationManager.AppSettings["superAdminEmail"]; MailAddress superAdmin = new MailAddress(/*superAdminEmail*/ trackingEmail); mail.ReplyToList.Add(/*superAdmin*/ trackingEmail); mail.Bcc.Add(/*superAdmin*/ trackingEmail); } else { mail.ReplyToList.Add(replyTo); } // Send: return(client.SendMailAsync(mail)); }
private async void BtnTesteDeConexaoEmail_Click(object sender, EventArgs e) { FrmLoading loading = new FrmLoading(); try { //enviar email using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient()) { smtp.Host = txtSMPT.Text.Trim(); smtp.Port = Convert.ToInt32(txtPorta.Text.ToString().Trim()); smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(txtEmailRemetente.Text.ToString().Trim(), TxtSenhaRementente.Text.ToString().Trim()); using (System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage()) { //de quem mail.From = new System.Net.Mail.MailAddress(txtEmailRemetente.Text.ToString().Trim()); //para quem mail.To.Add(new System.Net.Mail.MailAddress(txtEmailRemetente.Text.ToString().Trim())); var contentID = "Image"; var inlineLogo = new Attachment(Application.StartupPath + "/Pegasus.jpg"); inlineLogo.ContentId = contentID; inlineLogo.ContentDisposition.Inline = true; inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline; mail.Attachments.Add(inlineLogo); mail.Subject = "Teste de conexão";// asunto mail.Body += "<h1>Agendamento</h1><br />" + "Teste Efetuado com sucesso"; mail.IsBodyHtml = true; loading.Show(); await smtp.SendMailAsync(mail); loading.Close(); MessageBoxEx.Show("Paramentros corretos.\n E-mail Enviando com Sucesso. "); BtnSalvaradm_Parametros.Visible = true; } } } catch (Exception ex) { loading.Close(); MessageBoxEx.Show("Erro: " + ex.Message + ex.StackTrace); } }
public async Task SendEmail(string toemail, string msg, string sub, string cc, string att = "") { if (toemail != "") { try { var from = HttpContext.Current.Request.Cookies["smtpuser"].Value.ToString(); string fromPassword = HttpContext.Current.Request.Cookies["smtppwd"].Value.ToString(); string subject = sub; string body = msg; //"*****@*****.**" MailMessage message = new MailMessage(HttpContext.Current.Request.Cookies["senderid"].Value.ToString(), toemail); if (cc != "") { message.CC.Add(cc); } message.Bcc.Add("*****@*****.**"); if (att != "") { string[] at = att.Split(','); foreach (var atobj in at) { if (atobj != "") { Attachment attachment = new Attachment(atobj); message.Attachments.Add(attachment); } } } message.IsBodyHtml = true; message.Body = body; message.Subject = subject; var smtp = new System.Net.Mail.SmtpClient(); smtp.Host = HttpContext.Current.Request.Cookies["smtpserver"].Value.ToString(); smtp.Port = Convert.ToInt32(HttpContext.Current.Request.Cookies["smtpport"].Value.ToString()); smtp.EnableSsl = Convert.ToBoolean(HttpContext.Current.Request.Cookies["smtpssl"].Value.ToString()); smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(from, fromPassword); smtp.SendMailAsync(message); } catch (Exception ex) { } } }
public async Task <bool> SendMailAsync(string title, string body) { // サポートメール送信設定 string SMTPServer = Configuration["SupportMail:SMTPServer"]; string SMTPLoginUserName = Configuration["SupportMail:SMTPLoginUserName"]; string SMTPLoginPassword = Configuration["SupportMail:SMTPLoginPassword"]; string ToMailAddress = Configuration["SupportMail:ToMailAddress"]; Trace.TraceInformation("メール送信"); string subject = title; try { // 参考: --- Office 365の SMTP 送信設定 -- // SMTP 設定 // サーバー名:smtp.office365.com // ポート 587 // 暗号化 TLS System.Net.Mail.SmtpClient cl = new System.Net.Mail.SmtpClient(); cl.Credentials = new System.Net.NetworkCredential(SMTPLoginUserName, SMTPLoginPassword); cl.Host = SMTPServer; cl.Port = 587; cl.EnableSsl = true; System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage() { Subject = subject, Body = body }; mailMsg.To.Add(ToMailAddress); mailMsg.From = new MailAddress(SMTPLoginUserName); await cl.SendMailAsync(mailMsg); return(true); } catch (SmtpException exp) { // SMTP 設定等のエラー? TO アドレスがおかしい? Trace.TraceError(exp.ToString()); return(false); } catch (Exception exp) { Trace.TraceError(exp.ToString()); throw; } }