public static async Task ExecuteAsync(EmailModel model, SmtpConfig config) { var from = new MailboxAddress(Configuration.Name, Configuration.EmailAddress); var to = new MailboxAddress(model.To); MimeMessage message = new MimeMessage(); message.From.Add(from); message.To.Add(to); message.Subject = model.Subject; message.Body = model.IsHtml ? new BodyBuilder { HtmlBody = model.Body }.ToMessageBody() : new TextPart("plain") { Text = model.Body }; using (var client = new SmtpClient()) { if (!config.UseSsl) { client.ServerCertificateValidationCallback = (object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true; } await client.ConnectAsync(config.Host, config.Port, config.UseSsl).ConfigureAwait(false); client.AuthenticationMechanisms.Remove("XOAUTH2"); if (!string.IsNullOrWhiteSpace(config.Username)) { await client.AuthenticateAsync(config.Username, config.Password).ConfigureAwait(false); } await client.SendAsync(message).ConfigureAwait(false); await client.DisconnectAsync(true).ConfigureAwait(false); } }
async Task IEmailSenderService.SendEmailAsync(string email, string nombre, string ciudad, string fecha) { MailRequest mail = new MailRequest(); mail.Email = email; mail.Subject = "Test"; mail.Body = "Estimado " + nombre + "Hemos recibido sus datos y nos pondremos en contacto con" + "usted en la brevedad posible. Enviaremos un correo con información a su cuenta: " + email + "<br>" + "Atte. Green Leaves" + ciudad + "a " + fecha; try { var message = new MimeMessage(); message.From.Add(new MailboxAddress(_smtpSettings.SenderName, _smtpSettings.SenderEmail)); message.To.Add(new MailboxAddress("", mail.Email)); message.Subject = mail.Subject; message.Body = new TextPart("html") { Text = mail.Body }; using (var client = new SmtpClient()) { await client.ConnectAsync(_smtpSettings.Server); await client.AuthenticateAsync(_smtpSettings.Username, _smtpSettings.Password); await client.SendAsync(message); await client.DisconnectAsync(true); } } catch (Exception) { throw; } }
/// <inheritdoc/> public async Task SendAsync( string receiverName, string receiverEmail, string subject, string content, string senderEmail = null, string senderName = null) { var msg = new MimeMessage(); msg.To.Add(new MailboxAddress(receiverName, receiverEmail)); msg.From.Add( new MailboxAddress( senderName ?? options.SystemSenderName, senderEmail ?? options.SystemSenderEmailAddress)); msg.Subject = subject; msg.Body = new TextPart(TextFormat.Html) { Text = content }; var ssl = Enum.Parse <SecureSocketOptions>(options.Ssl); using (var smtp = new SmtpClient()) { await smtp.ConnectAsync(options.Host, options.Port, ssl); if (!string.IsNullOrWhiteSpace(options.AuthUsername)) { await smtp.AuthenticateAsync(options.AuthUsername, options.AuthPassword); } await smtp.SendAsync(msg); TrackEvent("SMTPSENDER-SENT", msg); } }
public async Task SendEmailAsync(string name, string email, string subject, string bodyMessage) { try { var message = new MimeMessage(); message.From.Add(new MailboxAddress("TeamTryLog", _settings.FromEmail)); message.To.Add(new MailboxAddress(name, email)); message.Subject = subject; message.Body = new TextPart("html") { Text = bodyMessage }; using (var client = new SmtpClient()) { // Accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; await client.ConnectAsync(_settings.PrimaryDomain); // Note: only needed if the SMTP server requires authentication await client.AuthenticateAsync(_settings.Email.ToString(), _settings.Password.ToString()); await client.SendAsync(message); await client.DisconnectAsync(true); } } catch (Exception ex) { // TODO: handle exception throw new InvalidOperationException(ex.Message); } }
private async Task <SendEmail> SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); var SMTP = Configuration.GetSection("SMTP"); emailMessage.From.Add(new MailboxAddress(SMTP.GetValue <string>("Name"), SMTP.GetValue <string>("UserName"))); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; var sendEmail = new SendEmail(); using (var client = new SmtpClient()) { try { await client.ConnectAsync(SMTP.GetValue <string>("Host"), SMTP.GetValue <int>("Port"), SMTP.GetValue <bool>("UseSsl")); await client.AuthenticateAsync(SMTP.GetValue <string>("UserName"), SMTP.GetValue <string>("Password")); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); sendEmail.Result = Result.Ok; } catch (Exception e) { sendEmail.FailedMessage = e.Message; sendEmail.Result = Result.Failed; } } return(sendEmail); }
public async Task SendEmailAsync(string email, string subject, string message) { try { var mimeMessage = new MimeMessage(); mimeMessage.From.Add(new MailboxAddress(emailSettings.UsernameEmail, emailSettings.FromEmail)); mimeMessage.To.Add(new MailboxAddress(email)); mimeMessage.Subject = subject; mimeMessage.Body = new TextPart("html") { Text = message }; using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; if (env.IsDevelopment()) { await client.ConnectAsync(emailSettings.PrimaryDomain, emailSettings.PrimaryPort, true); } else { await client.ConnectAsync(emailSettings.PrimaryDomain); } await client.AuthenticateAsync(emailSettings.UsernameEmail, emailSettings.UsernamePassword); await client.SendAsync(mimeMessage); await client.DisconnectAsync(true); } } catch (Exception ex) { throw new InvalidOperationException(ex.Message); } }
public async Task Execute( string email, string recipientName, string subject, string message) { SmtpCredentials?credentials = await _smtpCredentialManager.FetchCredentialsAsync(); if (credentials == null) { throw new Exception("SMTP credentials are not configured"); } MimeMessage mail = new MimeMessage(); mail.From.Add(new MailboxAddress("No Reply", credentials.SenderAddress)); mail.To.Add(new MailboxAddress(recipientName, email)); mail.Subject = subject; BodyBuilder bodyBuilder = new BodyBuilder(); bodyBuilder.TextBody = message; mail.Body = bodyBuilder.ToMessageBody(); using (SmtpClient client = new SmtpClient()) { await client.ConnectAsync( credentials.Hostname, credentials.Port ); await client.AuthenticateAsync(credentials.Username, credentials.Password); await client.SendAsync(mail); await client.DisconnectAsync(true); } }
public async Task SendMailAsync(string address, string token) { MailOptions config = mailOptions.Value; if (!config.EnableMailing) { logger.LogWarning("Mailing is disabled. \"{0}\" will not receive the token \"{1}\".", address, token); return; } string url = GetConfirmationUrl(token).AbsoluteUri; var message = new MimeMessage(); message.From.Add(new MailboxAddress(config.SenderName, config.SenderAddress)); message.To.Add(new MailboxAddress(address)); message.Subject = "Confirm your email address"; BodyBuilder builder = new BodyBuilder { TextBody = GetMailText() .Replace("$ADDRESS", address, StringComparison.Ordinal) .Replace("$URL", url, StringComparison.Ordinal), HtmlBody = GetMailHtml() .Replace("$ADDRESS", address, StringComparison.Ordinal) .Replace("$URL", url, StringComparison.Ordinal) }; message.Body = builder.ToMessageBody(); using var client = new SmtpClient(); await client.ConnectAsync(config.SmtpHost, config.SmtpPort, config.UseSsl).ConfigureAwait(false); await client.AuthenticateAsync(config.SmtpUsername, config.SmtpPassword).ConfigureAwait(false); await client.SendAsync(message).ConfigureAwait(false); await client.DisconnectAsync(quit : true).ConfigureAwait(false); }
public static async Task MailAsync(string from, IEnumerable <string> to, string subject, string content, MailContentType contentType, string smtpHost, int smtpPort, string userName, string password) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(from)); to.ToList().ForEach(addr => message.To.Add(new MailboxAddress(addr))); message.Subject = subject; var builder = new BodyBuilder(); if (contentType == MailContentType.Plain) { builder.TextBody = content; } else { builder.HtmlBody = content; } message.Body = builder.ToMessageBody(); try { using (var client = new SmtpClient()) { await client.ConnectAsync(smtpHost, smtpPort, true); await client.AuthenticateAsync(userName, password); await client.SendAsync(message); await client.DisconnectAsync(true); } } catch (Exception ex) { ExceptionlessUtil.Warn(ex, "邮件发送失败,请检查配置"); } }
public async Task SendMail(string to, string subject, string message) { try { var smtpHost = _configuration["Email:SMTPHost"]; var smtpPort = int.Parse(_configuration["Email:SMTPPort"]); var smtpSsl = bool.Parse(_configuration["Email:SMTPSsl"]); var smtpLogin = _configuration["Email:SMTPLogin"]; var smtpPassword = _configuration["Email:SMTPPassword"]; var mailFrom = _configuration["Email:SMTPFrom"]; var mailMessage = new MimeMessage { Subject = subject, Body = new TextPart(TextFormat.Plain) { Text = message } }; mailMessage.From.Add(new MailboxAddress(mailFrom, smtpLogin)); mailMessage.To.Add(new MailboxAddress(to)); using (var smtp = new SmtpClient()) { await smtp.ConnectAsync(smtpHost, smtpPort, smtpSsl); smtp.AuthenticationMechanisms.Remove("XOAUTH2"); await smtp.AuthenticateAsync(smtpLogin, smtpPassword); await smtp.SendAsync(mailMessage); } } catch (Exception e) { _logger.LogError(e, "Error sending email"); } }
public async Task SendEmailAsync(string email, string subject, string body) { try { var message = new MimeMessage(); message.From.Add(new MailboxAddress(_smtpSettings.SenderName, _smtpSettings.SenderEmail)); message.To.Add(new MailboxAddress(email)); message.Subject = subject; message.Body = new TextPart("html") { Text = body }; using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; if (_env.IsDevelopment()) { await client.ConnectAsync(_smtpSettings.Server, _smtpSettings.Port, true); } else { await client.ConnectAsync(_smtpSettings.Server); } await client.AuthenticateAsync(_smtpSettings.Username, _smtpSettings.Password); await client.SendAsync(message); await client.DisconnectAsync(true); } } catch (Exception e) { throw new InvalidOperationException(e.Message); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Администрация сайта", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 587, false); await client.AuthenticateAsync(_config.GetValue <string>("AdminEmail:Login"), _config.GetValue <string>("AdminEmail:Password")); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Fitroom administration", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 587, false); await client.AuthenticateAsync("*****@*****.**", "Zb_24081973"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Администрация сайта", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 25, false); await client.AuthenticateAsync("*****@*****.**", "Golovachuk123"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Адміністрація сайта Infinity", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", "590g50y89A"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Collector email service", _configuration["ServiceEmail"])); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync(_configuration["SMTPServer"], 25, false); await client.AuthenticateAsync(_configuration["ServiceEmail"], _configuration["EmailPassword"]); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("OrdersSystem", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", PASSWORD); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public static async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Готельна система \"HotelLocker\"", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 587, false); await client.AuthenticateAsync("*****@*****.**", "_Aa123456"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Guitar Shop", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", "Slon_100"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Service administration", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.yandex.ru", 465, true); await client.AuthenticateAsync("*****@*****.**", "admin123456Ars"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("FreelanceService", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress(email, email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 465, true); await client.AuthenticateAsync("*****@*****.**", "Looser14889235876"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(_settings.Value.SMTPAccount)); emailMessage.To.Add(new MailboxAddress(email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart("plain") { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync(_settings.Value.SMTPServer, _settings.Value.SMTPPort, false); await client.AuthenticateAsync(_settings.Value.SMTPAccount, _settings.Value.SMTPPassword); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Administration", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 25, false); await client.AuthenticateAsync("*****@*****.**", "furatp1993"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Administrator", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Text) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.ukr.net", 465, true); await client.AuthenticateAsync("*****@*****.**", "k62FORhKA7HPXv8L"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Администрация сайта", "*****@*****.**")); //тут e-mail отправителя emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.mail.ru", 465, true); await client.AuthenticateAsync("*****@*****.**", "password");//аутентификация аккаунта e-mail'а отправителя, здесь нужно указать свой e-mail и пароль await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string _email, string _subject, string _htmlMessage) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Authorization App", Options.Gmail)); emailMessage.To.Add(new MailboxAddress("", _email)); emailMessage.Subject = _subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = _htmlMessage }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 587, false); await client.AuthenticateAsync(Options.Gmail, Options.Password); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(_configuration.AuthorName, _configuration.Email)); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync(_configuration.Host, _configuration.Port, _configuration.EnableSsl); await client.AuthenticateAsync(_configuration.Email, _configuration.Password); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Администрация сайта", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", "rodionegor1337"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Site Administration", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 465, true); await client.AuthenticateAsync("*****@*****.**", "yjbvcjhciggkfqea"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task SendEmailAsync(string email, string subject, string message) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Администрация сайта", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress("", email)); emailMessage.Subject = subject; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = message }; using (var client = new SmtpClient()) { await client.ConnectAsync("smtp.gmail.com", 587, SecureSocketOptions.Auto); await client.AuthenticateAsync("*****@*****.**", "penda1977"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }