private SmtpClient CreateSmtpClient() { SmtpServer server = new SmtpServer(txtSmtpServer.Text.Trim()); server.User = txtSMTPUser.Text.Trim(); server.Password = txtSMTPPwd.Text.Trim(); SmtpClient client = new SmtpClient(); client.Connect(server); return client; }
private void Send(MimeMessage mailMessage) { using (var client = new SmtpClient()) { try { client.Connect(_emailConfig.SmtpServer, _emailConfig.Port, true); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(_emailConfig.UserName, _emailConfig.Password); client.Send(mailMessage); } catch { //log an error message or throw an exception or both. throw; } finally { client.Disconnect(true); client.Dispose(); } } }
private async Task SendEmailAsync(string subject, string body, string receiverEmail) { var mailMessage = new MimeMessage { Subject = subject, Body = new TextPart("plain") { Text = body } }; mailMessage.From.Add(new MailboxAddress("Aurora", "*****@*****.**")); mailMessage.To.Add(new MailboxAddress(receiverEmail, receiverEmail)); using (var smtpClient = new SmtpClient()) { smtpClient.Connect("smtp.gmail.com", 587, false); smtpClient.Authenticate("*****@*****.**", "aurora1234"); await smtpClient.SendAsync(mailMessage); smtpClient.Disconnect(true); } }
private void Send(MimeMessage emailMessage) { using (var client = new SmtpClient()) { try { client.Connect(_emailConifg.SmtpServer, _emailConifg.Port, true); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(_emailConifg.UserName, _emailConifg.Password); client.Send(emailMessage); } catch { throw; } finally { client.Disconnect(true); client.Dispose(); } } }
private void Send(MimeMessage mailMessage) { using (var client = new SmtpClient()) { try { client.Connect(_mailSettings.SmtpHost, _mailSettings.SmtpPort, SecureSocketOptions.StartTls); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(_mailSettings.SmtpUser, _mailSettings.SmtpPassword); client.Send(mailMessage); } catch (System.Exception ex) { _logger.LogError(ex.Message); //throw new ApiException(ex.Message); } finally { client.Disconnect(true); client.Dispose(); } } }
public async Task <IActionResult> Index() { ///Para envío de correo var mensaje = new MimeMessage(); mensaje.From.Add(new MailboxAddress("Test envio email", "*****@*****.**")); mensaje.To.Add(new MailboxAddress("Test enviado", "*****@*****.**")); mensaje.Subject = "Test email asp.net core"; mensaje.Body = new TextPart("plain") { Text = "Hola saludos desde crud" }; using (var cliente = new SmtpClient()) { cliente.Connect("smtp.gmail.com", 587); cliente.Authenticate("*****@*****.**", "Die22coK"); cliente.Send(mensaje); cliente.Disconnect(true); } return(View(await _context.Usuario.ToListAsync())); }
public void Send() { using (var client = new SmtpClient()) { // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect(SmtpConfigurationOptions.Server, SmtpConfigurationOptions.Port, SmtpConfigurationOptions.UseSsl); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH2"); if (SmtpConfigurationOptions.RequiresAuthentication) { // Note: only needed if the SMTP server requires authentication client.Authenticate(SmtpConfigurationOptions.User, SmtpConfigurationOptions.Password); } client.Send(this); client.Disconnect(true); } }
public void Send_Email_Test() { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Anuraj", "*****@*****.**")); message.To.Add(new MailboxAddress("ttt", "*****@*****.**")); message.Subject = "Hello World - A mail from ASPNET Core"; message.Body = new TextPart("plain") { Text = "Hello World - A mail from ASPNET Core" }; using (var client = new SmtpClient()) { //client.QueryCapabilitiesAfterAuthenticating = false; client.Connect("smtp.qq.com", 25, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.Authenticate("*****@*****.**", ""); client.Send(message); client.Disconnect(true); } }
public Task SendEmailAsync(string email, string subject, string messageBody) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(GlobalConstants.MyOperatingEmailName, GlobalConstants.MyOperatingEmail)); message.To.Add(new MailboxAddress(email)); message.Subject = subject; message.Body = new TextPart("plain") { Text = messageBody.ToString() }; using (var client = new SmtpClient()) { client.Connect(GlobalConstants.EmailProviderOperatingEmail, GlobalConstants.PortNumberOperatingEmail); client.Authenticate(GlobalConstants.MyOperatingEmail, GlobalConstants.MyOperatingEmailPassword); client.Send(message); client.Disconnect(true); } return(Task.CompletedTask); }
public async Task SendEmailAsync(string email, string subject, string msg) { // Plug in your email service here to send an email. var message = new MimeMessage(); message.From.Add(new MailboxAddress("*****@*****.**", "*****@*****.**")); message.To.Add(new MailboxAddress("Anuraj", email)); message.Subject = subject; var bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = msg; message.Body = bodyBuilder.ToMessageBody(); await Task.FromResult(0); using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate("*****@*****.**", "1qa2ws3ed4rf5tg"); client.Send(message); client.Disconnect(true); } }
public Task SendContactEmailAsync(string email, string subject, string htmlMessage) { if (!string.IsNullOrEmpty(email)) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(email)); message.To.Add(new MailboxAddress("*****@*****.**")); message.Subject = subject; message.Body = new TextPart("html") { Text = htmlMessage }; using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); client.Authenticate("*****@*****.**", "agmadmtp"); client.Send(message); client.Disconnect(true); } return(Task.CompletedTask); } throw new NotImplementedException(); }
private static bool SendMail(MimeMessage mailMessage, MailConfig config) { try { var smtpClient = new SmtpClient(); // 设置超时时间 smtpClient.Timeout = 10 * 1000; // 连接到远程smtp服务器 smtpClient.Connect(config.Host, config.Port, MailKit.Security.SecureSocketOptions.None); smtpClient.Authenticate(config.Address, config.Password); // 发送邮件 smtpClient.Send(mailMessage); smtpClient.Disconnect(true); return(true); } catch { throw; } }
public string SendEmail(dynamic body) { string msg = body.msg; string name = body.name; string email = body.email; string subject = body.Subject; var message = new MimeMessage(); message.From.Add(new MailboxAddress("*****@*****.**")); message.To.Add(new MailboxAddress("*****@*****.**")); message.Subject = subject; message.Body = new TextPart("html") { Text = "From " + name + " at " + email + "<br> " + msg }; using (var client = new SmtpClient()){ client.Connect("smtp.gmail.com", 587); client.Authenticate("*****@*****.**", "dfcz11BN"); client.Send(message); client.Disconnect(false); } return("Success"); }
private static void SentMailToRegistered(ApplicationUser user) { //Qeydiyyatdan kecmish user'lere auto Email gonderilir var message = new MimeMessage(); message.From.Add(new MailboxAddress("HrPayrollSystem", "*****@*****.**")); //qeydiyyatda input'a daxil olunan email'e uygun olarag message.To.Add(new MailboxAddress(user.UserName, user.Email)); message.Subject = "Qeydiyyatdan keçdiniz"; message.Body = new TextPart("plain") { Text = "Siz insan resurları və əmək haqqının hesablanması sistemində qeydiyyatdan keçdiniz." }; using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); //smtp hostu ve 587ci port client.Authenticate("*****@*****.**", "HrPrSystem123"); //email ve parol client.Send(message); client.Disconnect(true); } }
public void Enviar(string destinatario, string assunto, string mensagemHtml) { var message = new MimeMessage(); message.From.Add(new MailboxAddress(configuracaoEmail.NomeRemetente, configuracaoEmail.EmailRemetente)); message.To.Add(new MailboxAddress(destinatario)); message.Subject = assunto; message.Body = new TextPart("html") { Text = mensagemHtml }; using (var client = new SmtpClient()) { client.Connect(configuracaoEmail.ServidorSmtp, configuracaoEmail.Porta, configuracaoEmail.UsarTls); client.Authenticate(configuracaoEmail.Usuario, configuracaoEmail.Senha); client.Send(message); client.Disconnect(true); } }
public static void SendEmail(IConfiguration configuration, string receiverName, string receiverEmail, string subject, string message) { var email = new MimeMessage(); email.From.Add(new MailboxAddress(configuration.GetValue <string>("EmailSettings:Name"), configuration.GetValue <string>("EmailSettings:Email"))); email.To.Add(new MailboxAddress(receiverName, receiverEmail)); email.Subject = subject; email.Body = new TextPart("plain") { Text = message }; using (var client = new SmtpClient()) { client.Connect(configuration.GetValue <string>("SmtpSettings:ServerAddress"), int.Parse(configuration.GetValue <string>("SmtpSettings:Port")), false); client.Authenticate(configuration.GetValue <string>("EmailSettings:Email"), configuration.GetValue <string>("EmailSettings:Password")); client.Send(email); } }
private ApiResult <string> Send(MimeMessage mailMessage) { using (var client = new SmtpClient()) { try { client.Connect(_emailConfiguration.SmtpServer, _emailConfiguration.Port, true); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(_emailConfiguration.UserName, _emailConfiguration.Password); client.Send(mailMessage); return(new ApiResultSuccess <string>()); } catch (Exception e) { return(new ApiResultErrors <string>(e.Message)); } finally { client.Disconnect(true); client.Dispose(); } } }
/// <summary> /// 连接服务器 /// </summary> /// <param name="mailBodyEntity">邮件内容</param> /// <param name="sendServerConfiguration">发送配置</param> /// <param name="client">客户端对象</param> /// <param name="sendResultEntity">发送结果</param> public static void Connection(MailBodyEntity mailBodyEntity, SendServerConfigurationEntity sendServerConfiguration, SmtpClient client, SendResultEntity sendResultEntity) { try { client.Connect(sendServerConfiguration.SmtpHost, sendServerConfiguration.SmtpPort, sendServerConfiguration.IsSsl); } catch (SmtpCommandException ex) { sendResultEntity.ResultInformation = $"尝试连接时出错:{0}" + ex.Message; sendResultEntity.ResultStatus = false; } catch (SmtpProtocolException ex) { sendResultEntity.ResultInformation = $"尝试连接时的协议错误:{0}" + ex.Message; sendResultEntity.ResultStatus = false; } catch (Exception ex) { sendResultEntity.ResultInformation = $"服务器连接错误:{0}" + ex.Message; sendResultEntity.ResultStatus = false; } }
private static void SendMail(string subject, MailboxAddress reciever, string contents) { var message = new MimeMessage(); message.To.Add(reciever); message.From.Add(new MailboxAddress("AnnSmart", "*****@*****.**")); message.Subject = subject; message.Body = new TextPart("plain") { Text = contents }; using (var client = new SmtpClient()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp-mail.outlook.com", 587, false); client.Authenticate("*****@*****.**", "kh@ng1512");//Nnhm2018 client.Send(message); client.Disconnect(true); } }
public async Task SendEmailConfirmationAsync(User user, string confirmationLink) { MimeMessage message = new MimeMessage(); message.From.Add(new MailboxAddress(_emailSendingOptions.Email)); message.To.Add(new MailboxAddress(user.UserName, user.Email)); message.Subject = "Email confirmation"; message.Body = new TextPart("html") { Text = Markdown.ToHtml("# Hello\n#### To confirm email click this link - [click here](" + HtmlEncoder.Default.Encode(confirmationLink) + ")") }; using (var client = new SmtpClient()) { client.Connect(_emailSendingOptions.Host, _emailSendingOptions.Port, _emailSendingOptions.UseSSL); client.Authenticate(_emailSendingOptions.Email, _emailSendingOptions.Password); await client.SendAsync(message); client.Disconnect(true); } }
public bool SendDiet(string meal) { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Fit Life", "*****@*****.**")); message.To.Add(new MailboxAddress("michal", "*****@*****.**")); message.Subject = "Plan żywieniowy"; message.Body = new TextPart("plain") { Text = meal }; using (var client = new SmtpClient()) { client.Timeout = 10000; client.Connect("smtp.gmail.com", 587, false); client.Authenticate("*****@*****.**", "0172bbbb"); client.Send(message); client.Disconnect(true); } return(true); }
/// <summary> /// For send mail /// </summary> /// <param name="username"></param> /// <param name="to"></param> /// <param name="subject"></param> /// <param name="body"></param> /// <returns></returns> public async Task SendEmailAsync(string username, string to, string subject, string body) { var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Site admin", "*****@*****.**")); emailMessage.To.Add(new MailboxAddress(username, to)); emailMessage.Subject = subject; emailMessage.Body = new TextPart("plain") { Text = body }; using (var client = new SmtpClient()) { client.Connect(AllConstants.NameServer, AllConstants.NumberPort); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove(AllConstants.NameAuth2); // Note: only needed if the SMTP server requires authentication client.Authenticate(AllConstants.MailForAuthentificationServer, AllConstants.MailPasswordForAuthentificationServer); client.Send(emailMessage); client.Disconnect(true); } }
public static void SendRecoveryMail(User user, string recoveryToken) { //Send mail with mail and token link var message = new MimeMessage(); message.From.Add(new MailboxAddress("Komet Account Recovery Bot", recoveryMailAccount)); message.To.Add(new MailboxAddress(user.Name, user.Email)); message.Subject = "Restore Komet Account Password"; string link = "http://komet.cat/#/reset-password/" + user.Email + "/" + recoveryToken; message.Body = new TextPart("plain") { Text = "A password restoration of your account has been issued. If you want to change your password, go to this link:\n" + link }; using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); client.Authenticate("*****@*****.**", "glovodevpassword"); client.Send(message); client.Disconnect(true); } }
public void SendMessage(string email, object messageContent, string theme, string username = "") { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Полный Курс", _settings.Email)); message.To.Add(new MailboxAddress(username, email)); message.Subject = theme; message.Body = new TextPart(TextFormat.Html) { Text = MessageRenderer.RenderPartialToString(messageContent) }; using (var client = new SmtpClient()) { client.Connect(_settings.SmtpAdress, _settings.SmtpPort); client.Authenticate(_settings.EmailLogin, _settings.EmailPassword); client.Send(message); client.Disconnect(true); } }
private bool SendEmail(RokonoConfig configurationDetails, string name, string email, string Subject, string body) { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Rokono Control", configurationDetails.Username)); message.To.Add(new MailboxAddress(name, email)); message.Subject = Subject; BodyBuilder bodyBuilder = new BodyBuilder(); bodyBuilder.HtmlBody = body; // bodyBuilder.TextBody = "Hello World!"; message.Body = bodyBuilder.ToMessageBody(); using (var client = new SmtpClient()) { client.Connect(configurationDetails.SMTP, int.Parse(configurationDetails.SmtpPort), true); client.Authenticate(configurationDetails.Username, configurationDetails.Password); client.Send(message); client.Disconnect(true); } return(true); }
public void SendMail(NotificationMetadata _notificationMetadata, string receiver, string receiverName, string subject, MimeKit.Text.TextFormat textFormat, string content, string ccName, string cc, List <DigitalizedFile> digitalizedFiles) { EmailMessage message = new EmailMessage(); message.Sender = new MailboxAddress("Happy Gigas", _notificationMetadata.Sender); message.Reciever = new MailboxAddress(receiverName, receiver); message.Cc = new MailboxAddress(ccName, cc); message.Subject = subject; message.Content = content; var mimeMessage = CreateMimeMessageFromEmailMessage(message, textFormat, digitalizedFiles); using (SmtpClient smtpClient = new SmtpClient()) { smtpClient.Connect(_notificationMetadata.SmtpServer, _notificationMetadata.Port, true); smtpClient.Authenticate(_notificationMetadata.UserName, _notificationMetadata.Password); smtpClient.Send(mimeMessage); smtpClient.Disconnect(true); } }
public async Task SendEmailAsync(string emailTo, string subject, string htmlMessage) { var email = new MimeMessage(); email.Sender = MailboxAddress.Parse(_mailSettings.Mail); email.To.Add(MailboxAddress.Parse(emailTo)); email.Subject = subject; var builder = new BodyBuilder { HtmlBody = htmlMessage }; email.Body = builder.ToMessageBody(); using var smtp = new SmtpClient(); smtp.Connect(_mailSettings.Host, _mailSettings.Port, SecureSocketOptions.StartTls); smtp.Authenticate(_mailSettings.Mail, _mailSettings.Password); await smtp.SendAsync(email); smtp.Disconnect(true); }
public async Task SendEmailAsync(string email, string subject, string message) { var mimeMessage = new MimeMessage(); mimeMessage.From.Add(new MailboxAddress(senderName, senderEmail)); mimeMessage.Subject = !string.IsNullOrEmpty(subject) ? subject : "AfroStock"; mimeMessage.To.Add(new MailboxAddress(email)); BodyBuilder builder = new BodyBuilder { HtmlBody = message }; mimeMessage.Body = builder.ToMessageBody() ?? new TextPart("plain"); using var client = new SmtpClient(); client.Connect(smtp, port, SecureSocketOptions.None); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(senderEmail, password); await client.SendAsync(mimeMessage); _logger.LogInformation("message sent successfully..."); await client.DisconnectAsync(true); }
public async Task SendAsync(MailRequest request) { try { var email = new MimeMessage(); email.Sender = MailboxAddress.Parse(request.From ?? _config.From); email.To.Add(MailboxAddress.Parse(request.To)); email.Subject = request.Subject; var builder = new BodyBuilder(); builder.HtmlBody = request.Body; email.Body = builder.ToMessageBody(); using var smtp = new SmtpClient(); smtp.Connect(_config.Host, _config.Port, SecureSocketOptions.StartTls); smtp.Authenticate(_config.UserName, _config.Password); await smtp.SendAsync(email); smtp.Disconnect(true); } catch (System.Exception ex) { _logger.LogError(ex.Message, ex); } }
public async Task <IActionResult> ReplayMessage(int id, Contact sendContact) { var contact = await context.Contacts.FirstOrDefaultAsync(c => c.ID == id); var msg = new MimeMessage(); msg.From.Add(new MailboxAddress("fashionworld replay", "*****@*****.**")); msg.To.Add(new MailboxAddress(contact.Name, contact.Email)); msg.Subject = (contact.Supject); msg.Body = new TextPart(sendContact.Message); using (var client = new SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); client.Authenticate("*****@*****.**", ""); client.Send(msg); client.Disconnect(true); } return(View()); }
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()) { client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.gmail.com", 465, true); client.Authenticate("*****@*****.**", "qazwsx*963.Z"); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
private static bool emailServerLookup(string server) { IPAddress[] mx; try { mx = Dns.GetResolvedMXRecords(server); } catch (Win32Exception w32e) { Log.Instance.HandleException(w32e, LogLevel.Debug); return false; } if (mx.Length == 0) return false; foreach (IPAddress record in mx) { SmtpClient smtp = new SmtpClient(record); try { if (smtp.Connect().ResponseCode == SmtpResponseCode.ServiceReady && smtp.Hello().ResponseCode == SmtpResponseCode.Completed) return true; } catch (ApplicationException) { continue; } } return false; }