public static void SendEmailMime(string mailTo, string mailSubject, string mailContent, SendCompletedEventHandler sendCompleted = null) { // 设置发送方的邮件信息,例如使用网易的smtp string smtpServer = ConfigurationManager.AppSettings["SmtpServer"]; // SMTP服务器 string mailFrom = ConfigurationManager.AppSettings["MailFrom"]; // 登陆用户名 string userPassword = ConfigurationManager.AppSettings["MailPassword"]; //登陆密码 //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(mailFrom); mailMessage.To.Add(mailTo); mailMessage.Subject = mailSubject; mailMessage.Body = mailContent; //Create Smtp Client var mailer = new MimeMailer(smtpServer, 465); mailer.User = mailFrom; mailer.Password = userPassword; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back if (sendCompleted != null) { mailer.SendCompleted += sendCompleted; } mailer.SendMail(mailMessage); }
/// <summary> /// 发送激活邮件 /// </summary> /// <param name="addresser">发件人地址</param> /// <param name="addressPsswd">发件人密码</param> /// <param name="recipient">收件人地址</param> /// <param name="VerifyCode">随机验证码</param> public static void SSLMailSend(string addresser, string addressPsswd, string recipient, string VerifyCode) { try { var msg = new MimeMailMessage(); msg.From = new MimeMailAddress(addresser, "深圳凯华技术有限公司"); msg.To.Add(recipient); msg.Subject = "深圳凯华技术有限公司"; ////邮件正文 StringBuilder Content = new StringBuilder(); Content.Append("请进行邮箱验证,点击下面的链接激活您的邮箱,10分钟内有效:<br><a target='_blank' rel='nofollow' style='color: #0041D3; text-decoration: underline' href=http://120.78.49.234/MerchantPlatformApi/v/" + VerifyCode + ">点击这里</a>"); msg.Body = Content.ToString(); var mailer = new MimeMailer("smtp.mxhichina.com", 465); mailer.User = "******"; mailer.Password = "******"; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; mailer.SendCompleted += compEvent; // mailer.SendMailAsync(msg); mailer.SendMail(msg); } catch (MissingMethodException ex) { Console.WriteLine(ex.ToString()); } }
/// <project>Lettera22</project> /// <copyright company="Claudio Tortorelli"> /// Copyright (c) 2018 All Rights Reserved /// </copyright> /// <author>Claudio Tortorelli</author> /// <email>[email protected]</email> /// <web>http://www.claudiotortorelli.it</web> /// <date>Nov 2018</date> /// <summary> /// /// https://msdn.microsoft.com/it-it/library/system.net.mail.smtpclient(v=vs.110).aspx /// </summary> /// https://choosealicense.com/licenses/mit/ public static void Send(string toAddress, string fromAddress, string subject, string bodyText, string attachmentPath = "") { Globals.m_Logger.Info(toAddress); Globals.m_Logger.Info(fromAddress); Globals.m_Logger.Info(subject); Globals.m_Logger.Info(bodyText); //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(fromAddress); mailMessage.To.Add(toAddress); mailMessage.Subject = subject; mailMessage.Body = bodyText; if (attachmentPath.Length > 0 && File.Exists(attachmentPath)) { MimeAttachment attachMessage = new MimeAttachment(attachmentPath); mailMessage.Attachments.Add(attachMessage); } //Create Smtp Client var mailer = new MimeMailer(Globals.SMTPHost(), Globals.SMTPPort()); mailer.User = Globals.SMTPUsername(); mailer.Password = Globals.SMTPPassword(); mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; //Set a delegate function for call back mailer.SendCompleted += compEvent; mailer.SendMail(mailMessage); }
public static void SendEmail( string bookName, string strFooters, ref PackageHtml data, ref AccountData ac) { if (string.IsNullOrEmpty(bookName) || data.employeeData.Count == 0) { System.Windows.Forms.MessageBox.Show("没有数据可以发送!"); return; } //Create Smtp Client var mailer = new MimeMailer(ac.StrSMTP, ac.IPort); mailer.User = ac.StrUserName; mailer.Password = ac.StrPassword; mailer.SslType = SslMode.Ssl; mailer.AuthenticationMode = AuthenticationType.Base64; string footersstr = System.Text.RegularExpressions.Regex.Replace(strFooters, "[\r\n]", "<br>"); foreach (PackageHtml.Employee str in data.employeeData) { //Generate Message var mailMessage = new MimeMailMessage(); mailMessage.From = new MimeMailAddress(ac.StrUserName); mailMessage.To.Add(str.email); mailMessage.SubjectEncoding = Encoding.BigEndianUnicode; mailMessage.Subject = bookName; mailMessage.Body = str.data + footersstr; mailer.SendCompleted += AsynCompleteEvent; mailer.SendMail(mailMessage); } }
public string SendMail(string mail, string subject, string body) { //Generate Message var mymessage = CreateMessage(mail, subject, body); mailer.SendMail(mymessage); return(status); }
public static int?SendNotificationGlobal(string EmailTo, string Subject, string MessageContent, string ParamConfig) { int?status = 1; try { //var dbMAILCONFIG = Common.getSysParam(ParamConfig); string[] config = ParamConfig.Split(new char[] { '|' }); int port = Convert.ToInt16(config[1]); string Security = config[5]; if (!string.IsNullOrEmpty(EmailTo)) { var mymessage = new MimeMailMessage(); mymessage.From = new MimeMailAddress(config[2]); mymessage.To.Add(EmailTo); mymessage.Subject = Subject; mymessage.Body = MessageContent; mymessage.Priority = System.Net.Mail.MailPriority.High; var mailer = new MimeMailer(config[0], port); mailer.User = config[3]; mailer.Password = GeneralCommon.Decrypt(config[4]); if (Security == "TLS") { mailer.SslType = SslMode.Tls; } else if (Security == "SSL") { mailer.SslType = SslMode.Ssl; } else if (Security == "NONE") { mailer.SslType = SslMode.Ssl; } else { mailer.SslType = SslMode.Auto; } if (mailer.SslType == SslMode.None) { mailer.AuthenticationMode = AuthenticationType.PlainText; } else { mailer.AuthenticationMode = AuthenticationType.Base64; } mailer.SendCompleted += compEvent; mailer.SendMail(mymessage); status = 0; } } catch (Exception ex) { status = -1; //UIException.LogException(ex, "public static long SendNotification(string EmailTo,string Subject,string MessageContent)"); } return(status); }
private static bool sendingEmailAIM(EmailSettingInfo emailSetting, EmailInfo email, String emailBodyOrg, List <MailAddress> mailList) { Boolean success = false; MimeMailMessage mailMessage = getMimeMailMessage(emailSetting, email, emailBodyOrg, mailList); MimeMailer mailer = getMimeMailer(); System.IO.StreamWriter sw = Utilities.Utilities.CloseConsole(); try { mailer.SendMail(mailMessage); success = true; } catch (Exception ex) { email.Comments = ex.Message; } Utilities.Utilities.OpenConsole(sw); return(success); }
public void SendMessage(Guid messageId, string recipientEmail, string subject, string text) { var message = new MimeMailMessage { From = new MimeMailAddress(_address), Subject = subject, Body = text, IsBodyHtml = true, DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay, To = { recipientEmail }, Headers = { { Constants.MessageIdHeader, messageId.ToString() } }, BodyEncoding = Encoding.Unicode }; _smtpClient.SendCompleted += mailer_SendCompleted; _smtpClient.SendMail(message); }