private void buttonTestConnect_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxPassword.Text)) { MessageBox.Show("密码不能为空!"); return; } var message = new MimeMailMessage(); message.From = new MimeMailAddress(textBoxAccount.Text); message.To.Add(textBoxAccount.Text); message.Subject = "测试邮件"; message.SubjectEncoding = Encoding.UTF8; message.Body = @"这是在测试你的帐户设置时 Send SMTP 自动发送的电子邮件。"; int.TryParse(textBoxPort.Text, out int port); var mailer = new MimeMailer(textBoxsmpt.Text, port); mailer.User = textBoxAccount.Text; mailer.Password = textBoxPassword.Text; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendCompleted += AsyncaccountConfigEvent; mailer.SendMailAsync(message); }
public static void SendEmail(string subject, string message, string userTo) { try { subject = UtilClass.RemoveSign4VietnameseString(subject); userTo = userTo.ToLower(); //Generate Message if (userName.Count() == 0 || string.IsNullOrEmpty(host)) { return; } var mailMessage = new MimeMailMessage(); string smtpUserName = userName[UtilClass.GetRandomNumber(0, userName.Count() - 1)]; mailMessage.From = new MimeMailAddress(smtpUserName); mailMessage.To.Add(userTo); mailMessage.IsBodyHtml = true; mailMessage.Subject = subject; mailMessage.Body = message; //Create Smtp Client var mailer = new MimeMailer(host, port); mailer.User = smtpUserName; mailer.Password = password; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mailMessage); } catch (Exception ex) { LogClass.SaveError("ERROR SendEmail: " + ex); } }
public static void EmailSend(string mail, string subject, string body) { var host = "smtp.gmail.com"; var user = "******"; var pass = "******"; //Generate Message var mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(mail); mymessage.To.Add(mail); mymessage.Subject = subject; mymessage.Body = body; //Create Smtp Client var mailer = new MimeMailer(host, 465); mailer.User = user; mailer.Password = pass; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back // mailer.SendCompleted += compEvent; try { mailer.SendMailAsync(mymessage); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } }
private void SendEmail() { //Create message mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(mail); mymessage.To.Add(mail); mymessage.Subject = "test"; mymessage.Body = "body"; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mymessage); }
public static void SendEMail(MailArguments mailArgs, List <MimeAttachment> attachments, bool isSsl, Dictionary <string, string> headers) { var networkCredential = new NetworkCredential { Password = mailArgs.Password, UserName = mailArgs.MailFrom }; var mailMsg = new MimeMailMessage { Body = mailArgs.Message, Subject = mailArgs.Subject, IsBodyHtml = true // This indicates that message body contains the HTML part as well. }; mailMsg.To.Add(mailArgs.MailTo); if (headers.IsNotNullOrEmpty()) { foreach (var header in headers) { mailMsg.Headers.Add(header.Key, header.Value); } } if (attachments.IsNotNull()) { foreach (var attachment in attachments) { if (attachment.IsNotNull()) { mailMsg.Attachments.Add(attachment); } } } mailMsg.From = new MimeMailAddress(mailArgs.MailFrom); var mailer = new MimeMailer(mailArgs.SmtpHost, Convert.ToInt32(mailArgs.Port)); mailer.User = mailArgs.MailFrom; mailer.Password = mailArgs.Password; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendMailAsync(mailMsg); }
public static void SendReport(string subject, string message) { try { subject = UtilClass.RemoveSign4VietnameseString(subject); var userTo = mailReport.Split(',').ToList(); for (int i = 0; i < userTo.Count; i++) { //Generate Message if (userName.Count() == 0) { return; } var mailMessage = new MimeMailMessage(); string smtpUserName = userName[UtilClass.GetRandomNumber(0, userName.Count() - 1)]; mailMessage.From = new MimeMailAddress(smtpUserName); mailMessage.To.Add(userTo[i]); mailMessage.IsBodyHtml = true; mailMessage.Subject = ServerType + " " + subject; mailMessage.Body = message; //Create Smtp Client var mailer = new MimeMailer(host, port); mailer.User = smtpUserName; mailer.Password = password; if (SSL == "true") { mailer.SslType = SslMode.Ssl; } else { mailer.SslType = SslMode.None; } mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mailMessage); } } catch (Exception ex) { LogClass.SaveError("ERROR SendReport: " + ex); } }
public void EnviarEmailSSLImplicito(string email, string body, string sub, string rutaAdjunto) { var from = "*****@*****.**"; var host = "mail.tagor.cl"; var user = "******"; var pass = "******"; //Generate Message var mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(from); String[] AMailto = email.Split(';'); foreach (String mail in AMailto) { mymessage.To.Add(new MailAddress(mail)); } mymessage.Subject = sub; mymessage.Body = body; mymessage.SubjectEncoding = System.Text.Encoding.UTF8; mymessage.HeadersEncoding = System.Text.Encoding.UTF8; mymessage.IsBodyHtml = true; mymessage.Priority = MailPriority.High; if (rutaAdjunto != string.Empty) { MimeAttachment adj = new MimeAttachment(System.Web.HttpContext.Current.Server.MapPath(rutaAdjunto)); mymessage.Attachments.Add(adj); } //Create Smtp Client var mailer = new MimeMailer(host, 465); mailer.User = user; mailer.Password = pass; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mymessage); }
private static void SendEmail(string subject, string message) { //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(mailAddress); mailMessage.To.Add(userTo); mailMessage.Subject = subject; mailMessage.Body = message; //Create Smtp Client var mailer = new MimeMailer(host, 465); mailer.User = userName; mailer.Password = password; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mailMessage); }
public static void SendMail(MailUtilParaModel para, MailMessageModel message) { //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(para.MailAddress); //para.ReciverAddressList.ForEach(f=>mailMessage.To.Add(f)); mailMessage.To.Add(para.ReciverAddresses); mailMessage.Subject = message.Subject; mailMessage.Body = message.Text; //Create Smtp Client var mailer = new MimeMailer(para.ServerHost, para.ServerPort); mailer.User = para.LogonUserName; mailer.Password = para.Password; mailer.SslType = (SslMode)para.SSLType; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendMailAsync(mailMessage); }
public static void SendEmail(string subject, string body) { //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(Setting.emailParameter.From); mailMessage.To.Add(Setting.emailParameter.To); mailMessage.Subject = subject; mailMessage.Body = body; //Create Smtp Client var mailer = new MimeMailer(Setting.emailParameter.SMTPServer, Setting.emailParameter.Port); mailer.User = Setting.emailParameter.From; mailer.Password = Setting.emailParameter.Password; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMailAsync(mailMessage); }
public void SendEmail(string body, string subject, string address) { string mail = "*****@*****.**"; string pass = "******"; string host = "smtp.ukr.net"; //Generate Message var mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(mail); mymessage.To.Add(address); mymessage.Subject = subject; mymessage.Body = body; //Create Smtp Client var mailer = new MimeMailer(host, 465); mailer.User = mail; mailer.Password = pass; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendMailAsync(mymessage); }
public void SendMailAsync(string mail, string subject, string body) { var mymessage = CreateMessage(mail, subject, body); mailer.SendMailAsync(mymessage); }
static bool DataReceived(string ipPort, byte[] data) { Regex _re = new Regex(@"^(?<PRI>\<\d{1,3}\>)?(?<HDR>(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s[0-3][0-9]\s[0-9]{4}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2}\s[^ ]+?\s)?:\s(?<MSG>.+)?", RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline | RegexOptions.Compiled); Match m = _re.Match(Encoding.UTF8.GetString(data)); if (m.Success) { Message msg = new Message(); if (m.Groups["PRI"].Success) { string pri = m.Groups["PRI"].Value; int priority = Int32.Parse(pri.Substring(1, pri.Length - 2)); msg.Facility = (FacilityType)Math.Floor((double)priority / 8); msg.Severity = (SeverityType)(priority % 8); } else { msg.Facility = FacilityType.User; msg.Severity = SeverityType.Notice; } if (m.Groups["HDR"].Success) { string hdr = m.Groups["HDR"].Value.TrimEnd(); int idx = hdr.LastIndexOf(' '); msg.Datestamp = DateTime.ParseExact(hdr.Substring(0, idx), "MMM dd yyyy HH:mm:ss", null); msg.Hostname = hdr.Substring(idx + 1); } else { msg.Datestamp = DateTime.Now; } msg.Content = m.Groups["MSG"].Value; msg.RemoteIP = ipPort; msg.LocalDate = DateTime.Now; if (MessageReceived != null) { MessageReceived(msg); Dictionary <string, object> d1 = new Dictionary <string, object>(); d1.Add("host", msg.Hostname); d1.Add("facility", msg.Facility); d1.Add("severity", msg.Severity); d1.Add("date", msg.Datestamp); d1.Add("msg", msg.Content); Settings.Sql.Insert("logs", d1); try { //Generate Message var mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(Properties.Settings.Default.mailfrom); mymessage.To.Add(Properties.Settings.Default.mailto); mymessage.Subject = "ASA Log - " + msg.Hostname + " - " + msg.Severity; mymessage.Body = Encoding.UTF8.GetString(data); //Create Smtp Client var mailer = new MimeMailer(Properties.Settings.Default.mailserver, Properties.Settings.Default.mailport); mailer.User = Properties.Settings.Default.mailusername; mailer.Password = Properties.Settings.Default.mailpassword; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendMailAsync(mymessage); } catch (Exception ep) { MessageBox.Show(ep.Message, "Failed to send email with the following error:", MessageBoxButtons.OK); } } } return(true); }