/// <summary> /// This is the Back up plan for the above method /// Used Few years back with ASP /// Now obsalete method & substituted by System.Net.Mail namespace /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="subject"></param> /// <param name="body"></param> private static void SendMailAlt(string to, string from, string subject, string body) { System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage(); Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = ("mail.employersunity.com"); Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = "465"; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true"; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; // Edit username & password Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "******"; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "******"; Mail.To = to; Mail.From = from; Mail.Subject = subject; Mail.Body = body; Mail.BodyFormat = System.Web.Mail.MailFormat.Html; System.Web.Mail.SmtpMail.SmtpServer = "mail.employersunity.com"; System.Web.Mail.SmtpMail.Send(Mail); }
public static void SendMail(string to, string bbc, string subject, string messages, string smtp, string port, string from, string user, string password) { try { System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); mail.To = to; mail.Bcc = bbc; mail.From = from; mail.Subject = subject; mail.BodyEncoding = Encoding.GetEncoding("utf-8"); mail.BodyFormat = MailFormat.Html; mail.Body = messages; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = smtp; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = port; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = 1; // "true"; //mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"] = 60; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = user; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = password; //SmtpMail.SmtpServer = smtp; SmtpMail.Send(mail); } catch (Exception ex) { throw; } }
/// <summary> /// WebMail发邮件 /// </summary> /// <param name="fromMail">发件人邮箱地址</param> /// <param name="fromPwd">发件人邮箱密码</param> /// <param name="smtpStr">smtp服务器地址</param> /// <param name="toMail">收件人地址,支持群发,用";"隔开</param> /// <param name="subject">邮件主题</param> /// <param name="body">邮件正文</param> /// <param name="sendMode">邮件格式:0是纯文本,1是html格式化文本</param> /// <returns></returns> public static bool SendWebMail(string fromMail, string fromPwd, string smtpStr, string toMail, string subject, string body, string sendMode) { try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.From = fromMail; myMail.To = toMail; //myMail.Cc = ccMail;string ccMail, string bccMail,//抄送和密送 //myMail.Bcc = bccMail; myMail.Subject = subject; myMail.Body = body; myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html; //附件 //string ServerFileName = ""; //if (this.upfile.PostedFile.ContentLength != 0) //{ // string upFileName = this.upfile.PostedFile.FileName; // string[] strTemp = upFileName.Split('.'); // string upFileExp = strTemp[strTemp.Length - 1].ToString(); // ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp); // this.upfile.PostedFile.SaveAs(ServerFileName); // myMail.Attachments.Add(new MailAttachment(ServerFileName)); //} myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", fromMail); //发送方邮件帐户 myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", fromPwd); //发送方邮件密码 SmtpMail.SmtpServer = smtpStr; //"smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1); SmtpMail.Send(myMail); return(true); } catch { return(false); } }
/// <summary> /// Generic function to send mail /// </summary> /// <param name="smtpServer">SMTP Server Name/IP</param> /// <param name="from">From Email Address</param> /// <param name="to">To Email Address</param> /// <param name="subject">Subject</param> /// <param name="body">Body</param> /// <returns>bool</returns> public bool SendMail(string strSmtpServer, string strFrom, string strTo, string strSubject, string strBody) { MailMessage mailMsg = null; Boolean blnMailSent = false; try { mailMsg = new MailMessage(); mailMsg.From = strFrom; mailMsg.To = strTo; mailMsg.Cc = strFrom; mailMsg.Subject = strSubject; mailMsg.BodyFormat = MailFormat.Html; mailMsg.Body = strBody; if (strSmtpServer.Trim().Length != 0) { SmtpMail.SmtpServer = strSmtpServer; } SmtpMail.Send(mailMsg); blnMailSent = true; } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, Global .EXCEPTION_POLICY); if (rethrow) throw; } return blnMailSent; }
protected void ButtonSubmit_Click(object sender, System.EventArgs e) { Server.ScriptTimeout = 1000; Response.Flush(); SmtpMail.SmtpServer = "localhost"; MailMessage mail = new MailMessage(); mail.To = this.TextBoxTo.Text; mail.Cc = this.TextBoxCc.Text; mail.Bcc = this.TextBoxBcc.Text; mail.From = this.TextBoxFrom.Text; mail.Subject = this.TextBoxSubject.Text; mail.Body = this.TextBoxBody.Text; try { SmtpMail.Send(mail); Response.Write("<p><strong> The Mail has been sent to: </strong></p>"); Response.Write("• To: " + mail.To + "</br>"); Response.Write("• Cc: " + mail.Cc + "</br>"); Response.Write("• Bcc: " + mail.Bcc + "</br>"); } catch(System.Exception ex) { Response.Write("<p><strong>An erros has occured: " + ex.Message + "</strong><p>"); } Response.Flush(); }
public ActionResult SendEmail(string Name, string Phone, string Message, string Email, string Subject) { var emailmessage = new System.Web.Mail.MailMessage() { Subject = Name, Body = "From: " + Name + "\n Phone Number: " + Phone + "\n Job Description: " + Message + "\n Email: " + Email, From = "*****@*****.**", To = "*****@*****.**", BodyFormat = MailFormat.Text, Priority = System.Web.Mail.MailPriority.High }; var passWord = "******"; var email = new MailAddress("*****@*****.**", "Pablo"); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(email.Address, passWord) }; using (var mess = new System.Net.Mail.MailMessage(email, email) { Subject = Subject, Body = "From: " + Name + "\n Phone Number: " + Phone + "\n Job Description: " + Message + "\n Email: " + Email }) { smtp.Send(mess); } return(new EmptyResult()); }
public void EmailBodyGeneral(string toEmail, string subject, string txt) { try { MailMessage objMail = new MailMessage(); objMail.From = "EHR <*****@*****.**>"; objMail.To = toEmail; objMail.Subject = subject; objMail.BodyFormat = MailFormat.Html; objMail.Body = txt; SmtpMail.SmtpServer = "wczmail.wistron.com"; SmtpMail.Send(objMail); } catch (Exception e) { MailMessage objMail = new MailMessage(); objMail.From = "EHR <*****@*****.**>"; objMail.To = "EHR <*****@*****.**>"; objMail.Subject = subject; objMail.BodyFormat = MailFormat.Html; objMail.Body = "Email not deliver. <br />Did not deliver to: " + toEmail + e.Message; SmtpMail.SmtpServer = "wczmail.wistron.com"; SmtpMail.Send(objMail); } }
protected void Button3_Click(object sender, EventArgs e) { System.Web.Mail.MailMessage mailMsg = new System.Web.Mail.MailMessage { From = "*****@*****.**", To = "*****@*****.**", Subject = "Test email from ASP.net", Body = "Hi this is a test email" }; /* * mailMsg.From = "*****@*****.**"; * mailMsg.To = "*****@*****.**"; * mailMsg.From = Subject = "Test email from ASP.net"; * mailMsg.From = Body = "Hi this is a test email"; * */ //SmtpMail.SmtpServer = "smtp.gmail.com"; //SmtpMail.Send(mailMsg); var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "nationwideSophy"), EnableSsl = true }; client.Send("*****@*****.**", "*****@*****.**", "Test email from ASP.net", "Hi this is a test email"); }
public static bool sendMail(string from, string to, string subject, string body, bool isVietNam) { WriteLog("[sendMail]---------------Begin---------------"); WriteLog("[sendMail] From: " + from); WriteLog("[sendMail] Subject: " + subject); WriteLog("[sendMail] To: " + to); System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage(); msg.To = to; msg.From = from; msg.Body = body; msg.Subject = subject; if (isVietNam) { msg.BodyEncoding = Encoding.UTF8; } else { msg.BodyEncoding = Encoding.ASCII; } msg.BodyFormat = MailFormat.Html; SmtpMail.SmtpServer = Functions.GetConfig("SMTPServer"); SmtpMail.Send(msg); WriteLog("[sendMail] Success"); WriteLog("[sendMail]---------------End---------------"); return(true); }
public static void SendMail(string from, string to, string subject, string body, bool html) { if (Functions.IsEmpty(to)) { return; } string[] ss1 = to.Split(';'); foreach (string ss in ss1) { foreach (string s in ss.Split(',')) { try { System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage(); msg.To = s; msg.From = from; msg.Body = body; msg.Subject = subject; msg.BodyEncoding = Encoding.UTF8; msg.BodyFormat = html ? MailFormat.Html : MailFormat.Text; SmtpMail.SmtpServer = GetAppConfigByKey("SMTPServer"); SmtpMail.Send(msg); } catch (Exception ex) { } } } }
public static bool SendMailWeb(string fromEmail, string fromPwd, string toEmail, string smtpServer, string title, string content) { try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.From = fromEmail; myMail.To = toEmail;// ; myMail.Subject = title + DateTime.Now.ToString(); myMail.Body = content; myMail.BodyFormat = MailFormat.Html; myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", fromEmail); //发送方邮件帐户 myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", fromPwd); //发送方邮件密码 SmtpMail.SmtpServer = smtpServer; //"smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1); SmtpMail.Send(myMail); return(true); } catch (Exception ex) { return(false); } }
private static void SendEmail( string filePath ) { Console.Write( "Crash: Sending email..." ); try { MailMessage message = new MailMessage(); message.Subject = "Automated RunUO Crash Report"; message.From = "RunUO"; message.To = Emails; message.Body = "Automated RunUO Crash Report. See attachment for details."; message.Attachments.Add( new MailAttachment( filePath ) ); SmtpMail.SmtpServer = EmailServer; SmtpMail.Send( message ); Console.WriteLine( "done" ); } catch { Console.WriteLine( "failed" ); } }
/// <summary> /// �����ʼ� /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="isAsync"></param> private void SendMailMessage(string to, string from, string subject, string message, bool isAsync) { if (string.IsNullOrWhiteSpace(to)) throw new ArgumentNullException("to"); if (string.IsNullOrWhiteSpace(from)) throw new ArgumentNullException("from"); if (string.IsNullOrWhiteSpace(subject)) throw new ArgumentNullException("subject"); try { MailMessage mailMessage = new MailMessage(); mailMessage.From = from; mailMessage.To = to; mailMessage.Subject = subject; mailMessage.Body = message; mailMessage.BodyFormat = MailFormat.Html; mailMessage.BodyEncoding = System.Text.Encoding.UTF8; //�ʼ����ݱ��� SmtpMail.SmtpServer = this.SmtpServer; // �����ʼ��������˿� //��֤ mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //�Ƿ���Ҫ��֤��һ����Ҫ�� mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.UserName); //�Լ�������û��� mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.Password); //�Լ���������� SmtpMail.Send(mailMessage); } catch (Exception ex) { throw new Exception("�����ʼ�����", ex); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if ((tbxPhone.Text == "") && (tbxEmail.Text == "")) { CustomValidator1.IsValid = false; } else { SmtpMail.SmtpServer = "relay-hosting.secureserver.net"; MailMessage mm; mm = new MailMessage(); mm.BodyFormat = MailFormat.Html; mm.To = "*****@*****.**"; mm.From = "*****@*****.**"; mm.Subject = "New message generated from 1PromotionalProducts.com"; mm.Body = "*** THIS IS AN AUTOMATED EMAIL. DO NOT REPLY. ***<br /><br />"; mm.Body += "Name: " + tbxName.Text; if (tbxEmail.Text != "") { mm.Body += "<br /><br />Reply Email: " + tbxEmail.Text; } if (tbxPhone.Text != "") { mm.Body += "<br /><br />Phone Number: " + tbxPhone.Text; } mm.Body += "<br /><br />Comment/Question:<br />" + tbxBody.Text.Replace("\r", "<br />").Replace("\n", ""); SmtpMail.Send(mm); Response.Redirect("Default.aspx", true); } }
public static void SendExceptionMail(string strMessage, string strSource, string strStackTrace) { try { string strFromMailId = ConfigurationManager.AppSettings.Get("EmailFrom"); string strMailServer = ConfigurationManager.AppSettings.Get("SmtpClient"); string strMailUser = ConfigurationManager.AppSettings.Get("UID"); string strMailPwd = ConfigurationManager.AppSettings.Get("Pwd"); string vstrSubject = "CSWeb Integration - Exception"; string vstrBody = "<b>Message: </b>" + strMessage + "<br/><br/><b>Sourse: </b>" + strSource + "<br/><br/><b>StackTrace: </b>" + strStackTrace; string strMails = ConfigurationManager.AppSettings.Get("ErrorEmailTo"); MailMessage objMessage = new MailMessage(); if (strMailServer != "") { SmtpMail.SmtpServer = strMailServer; objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = strMailUser; objMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = strMailPwd; } objMessage.From = strFromMailId; objMessage.To = strMails; objMessage.Subject = vstrSubject; objMessage.Body = vstrBody; objMessage.BodyFormat = MailFormat.Html; SmtpMail.Send(objMessage); } catch (Exception exc) { } }
public bool Notifymail(string zip, string journal, string article, string error) { try { System.Web.Mail.MailMessage Msg = new System.Web.Mail.MailMessage(); // Sender e-mail address. Msg.From = "*****@*****.**"; // Recipient e-mail address. Msg.To = "[email protected],[email protected]"; //adding Msg.Cc = "*****@*****.**"; //o.To.Add("*****@*****.**"); //o.To.Add("*****@*****.**"); Msg.Subject = "MRW FTP Notification"; Msg.Body = "Ready Signal uploaded for " + journal + " | '" + article + "', orderID id is " + zip + " Error = " + error + " "; // your remote SMTP server IP. SmtpMail.SmtpServer = "192.168.1.79";//your ip address SmtpMail.Send(Msg); return(true); } catch (Exception ex) { report("Ready_FTP_Error", zip, ex.ToString()); ex.ToString(); return(false); } }
public static void SendMail(string to, string bbc, string subject, string messages, string smtp, string port, string from, string user, string password) { try { System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); mail.To = to; mail.Bcc = bbc; mail.From = from; mail.Subject = subject; mail.BodyEncoding = Encoding.GetEncoding("utf-8"); mail.BodyFormat = MailFormat.Html; mail.Body = messages; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = smtp; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = port; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = 1; // "true"; //mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"] = 60; mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = user; mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = password; SmtpMail.Send(mail); } catch (Exception) { HttpContext.Current.Response.Redirect("/InnerError.html", false); } }
/// <summary>Envia um mail</summary> public static bool Send( MailMessage message ) { try { if( message.From == null || message.From == "" ) { message.From = Mailer.From; } #if DEBUG_MAIL Log.log("----- SEND MAIL DEBUG ----------"); Log.log("To: {0}", message.To); Log.log("From: {0}", message.From); Log.log("Bcc: {0}", message.Bcc); Log.log("Title: {0}", message.Subject); Log.log("Message: {0}", message.Body); Log.log("-------------------------------"); #endif Log.log("Sending mail message '{0}'...", message.Subject ); SmtpMail.Send(message); Log.log("... Done!"); return true; } catch(System.Exception e) { ExceptionLog.log(e, false); return false; } }
public static void Sendmail(string emailTo, string subject, string body) { try { string smtpAddress = "smtp.fairygroup.co.th"; int portNumber = 25; bool enableSSL = true; string emailFrom = "*****@*****.**"; string password = "******"; //string emailTo = conf.ConfigValue; MailMessage Message = new MailMessage(); Message.To = password; Message.From = emailFrom; Message.Subject = subject; Message.Body = body; SmtpMail.SmtpServer = "smtp.fairygroup.co.th"; SmtpMail.Send(Message); } catch (System.Web.HttpException ehttp) { throw ehttp; //Console.WriteLine("{0}", ehttp.Message); //Console.WriteLine("Here is the full error message output"); //Console.Write("{0}", ehttp.ToString()); } }
/// <summary> /// 阿里云要用这种方式,要不然发不了,System.Net.Mail不支持Ssl /// </summary> /// <param name="mailTo"></param> /// <param name="mailSubject"></param> /// <param name="mailContent"></param> /// <returns></returns> public static bool SendEmail(string mailTo, string mailSubject, string mailContent) { log.Info(mailTo + " | " + mailContent); // 设置发送方的邮件信息,例如使用网易的smtp string smtpServer = "smtp.qq.com"; //SMTP服务器 string mailFrom = "*****@*****.**"; //登陆用户名 string userPassword = "******"; //登陆密码 System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); try { mail.To = mailTo; mail.From = mailFrom; mail.Subject = mailSubject; mail.BodyFormat = System.Web.Mail.MailFormat.Html; mail.Body = mailContent; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailFrom); //set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", userPassword); //set your password here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465); //set port mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); //set is ssl System.Web.Mail.SmtpMail.SmtpServer = smtpServer; System.Web.Mail.SmtpMail.Send(mail); return(true); } catch (Exception ex) { log.Info(ex); return(false); } }
public static String Send(StringBuilder strbBodyParam, String strSubjectParam, String strEmailAddrParam) { String strCurrentStatus = ""; // prepare message with the report MailMessage mmEmailMsg = new MailMessage(); mmEmailMsg.Body = strbBodyParam.ToString(); mmEmailMsg.From = SenderEmailAddr; mmEmailMsg.Subject = strSubjectParam; mmEmailMsg.To = strEmailAddrParam; // send email with the report // DirectSMTP.SmtpServer = "10.10.10.30"; // DirectSMTP.SmtpServer = "smtpgtwy.emcare.com"; // Changed SMTP server - 6/21/07, grf // DirectSMTP.SmtpServer = SmtpServerAddr; String strResponse = DirectSMTP.Send(mmEmailMsg); if (!strResponse.Equals("")) { strCurrentStatus = String.Format( "ERROR: Could not send email to {0} through {1}\r\n\r\n{2}.", strEmailAddrParam, DirectSMTP.SmtpServer, strResponse); } else { strCurrentStatus = String.Format("Sent report to email {0}", strEmailAddrParam); } return strCurrentStatus; }
public void SendToEmailOld() { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); message.Subject = Subject; message.BodyFormat = IsHtml ? MailFormat.Html : MailFormat.Text; // 设置邮件正文为html 格式 message.BodyEncoding = Encoding; message.Body = Content; // 设置邮件内容 message.From = FromEmail; message.To = ToEmail; String sendUser; int s = FromEmail.IndexOf('<'); int e = FromEmail.IndexOf('>'); if (s > 0 && e > 0) { FromEmail = FromEmail.Substring(s + 1, e - s - 1); } String[] EmailParts = FromEmail.Split("@".ToCharArray(), 2); sendUser = EmailParts[0]; message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置服务器需要身份验证 message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendUser); //设置用户名 message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", FromEmailPwd); //设置密码 SmtpMail.SmtpServer = SmtpServer; SmtpMail.Send(message); //发送邮件。 }
/// <summary> /// 发送邮件 /// </summary> /// <returns></returns> public bool Send() { mail = new System.Web.Mail.MailMessage(); try { mail.To = _To; mail.Cc = _CC; mail.From = _From; mail.Subject = _Subject; mail.BodyFormat = System.Web.Mail.MailFormat.Html; mail.Body = _Body; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //身份验证 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mail.From); //邮箱登录账号,这里跟前面的发送账号一样就行 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _Password); //这个密码要注意:如果是一般账号,要用授权码;企业账号用登录密码 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", _Port); //端口 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); //SSL加密 System.Web.Mail.SmtpMail.SmtpServer = _SmtpHost; //企业账号用smtp.exmail.qq.com thread = new System.Threading.Thread(SendThread); thread.Start(); return(true); } catch { return(false); } }
/// <summary> /// �����ʼ� /// </summary> /// <Author>Terminate</Author> /// <CreateTime>2006-10-1</CreateTime> /// <param name="MailFrom">������[�����˵�ַ]</param> /// <param name="MailTo">�����˵�ַ</param> /// <param name="MailSubject">�ż�����</param> /// <param name="MailBody">�ż�����</param> public static void SenddMail(string MailFrom,string MailTo,string MailSubject,string MailBody) { string SmtpServer,UserName,UserPwd; bool MailCheck; SmtpServer="mail.hbu.cn"; UserName="******"; UserPwd="hao@nic-hbu"; MailCheck=true; MailMessage MailObj=new MailMessage(); SmtpMail.SmtpServer=SmtpServer; if(MailCheck) { //��֤ MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");//��֤��ʽ1��֤��0����֤ //�û��� MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",UserName); //���� MailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",UserPwd); } MailObj.From =MailFrom; //������ MailObj.To =MailTo; //�ռ��� MailObj.Subject =MailSubject; //�ʼ����� MailObj.Priority =MailPriority.High; //�ʼ��ȼ� MailObj.BodyFormat =MailFormat.Html; //�ʼ����ݸ�ʽ MailObj.Body =MailBody; //�ʼ����� SmtpMail.Send(MailObj); }
public void SendMail(string recipient, string body) { string pGmailEmail = "*****@*****.**"; string pGmailPassword = "******"; string pTo = recipient; //[email protected] string pSubject = "Revature Housing Account"; string pBody = body; //Body MailFormat pFormat = MailFormat.Text; //Text Message string pAttachmentPath = string.Empty; //No Attachments System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); //sendusing: cdoSendUsingPort, value 2, for sending the message using //the network. //smtpauthenticate: Specifies the mechanism used when authenticating //to an SMTP //service over the network. Possible values are: //- cdoAnonymous, value 0. Do not authenticate. //- cdoBasic, value 1. Use basic clear-text authentication. //When using this option you have to provide the user name and password //through the sendusername and sendpassword fields. //- cdoNTLM, value 2. The current process security context is used to // authenticate with the service. myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", pGmailEmail); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", pGmailPassword); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = pGmailEmail; myMail.To = pTo; myMail.Subject = pSubject; myMail.BodyFormat = pFormat; myMail.Body = pBody; if (pAttachmentPath.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(pAttachmentPath); myMail.Attachments.Add(MyAttachment); myMail.Priority = System.Web.Mail.MailPriority.High; } SmtpMail.SmtpServer = "smtp.gmail.com:465"; SmtpMail.Send(myMail); }
public static void SendEmail(string from, string bcc, string cc, string subject, string body, string To = "") { string to = ""; if (String.IsNullOrEmpty(To)) { to = "*****@*****.**"; } else { to = To; } const string SERVER = "relay-hosting.secureserver.net"; System.Web.Mail.MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = from; oMail.To = to; oMail.Subject = subject; oMail.Body = body; oMail.BodyFormat = System.Web.Mail.MailFormat.Html; // enumeration oMail.Priority = System.Web.Mail.MailPriority.High; // enumeration oMail.Body += "Sent at: " + DateTime.Now; SmtpMail.SmtpServer = SERVER; SmtpMail.Send(oMail); oMail = null; // free up resources }
private void button1_Click(object sender, System.EventArgs e) { if (boxFrom.Text == defaultFrom || boxFrom.Text.Split('@').Length != 2) { MessageBox.Show("Please enter your email address."); return; } Hide(); MailMessage msg = new MailMessage(); msg.From = boxFrom.Text; msg.To = boxEmailTo.Text; msg.Subject = "NoxMapEditor Crash Report"; msg.Body = boxMessage.Text + (boxNotes.Text == "" ? "" : "\n\nNotes:\n" + boxNotes.Text); bool sent = false; foreach (string server in DnsLib.DnsApi.GetMXRecords(boxEmailTo.Text.Split('@')[1])) { SmtpMail.SmtpServer = server; try { SmtpMail.Send(msg); sent = true; break; } catch (Exception) {} } if (!sent) MessageBox.Show("Couldn't send mail message."); }
public void Send_Mail(string sMailID, string sSubject, string sBody) { NetworkCredential mailAuthentication = new NetworkCredential("*****@*****.**", "ajay123"); //NetworkCredential("*****@*****.**", "4nksmganesh136"); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); mailClient.Host = "smtpout.asia.secureserver.net"; //"smtp.mail.yahoo.com";// mailClient.Port = 587; //587,465,80,3535,25,995---not support secure connection at 80,3535 mailClient.EnableSsl = true; mailClient.UseDefaultCredentials = false; mailClient.Credentials = mailAuthentication; System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("*****@*****.**", sMailID, sSubject, sBody); mailClient.Send(MyMailMessage); const string SERVER2 = "relay-hosting.secureserver.net"; System.Web.Mail.MailMessage oMail2 = new System.Web.Mail.MailMessage(); oMail2.From = "*****@*****.**"; oMail2.To = sMailID; oMail2.Subject = sSubject; // "Acknowledgement"; oMail2.BodyFormat = System.Web.Mail.MailFormat.Html; // enumeration oMail2.Priority = System.Web.Mail.MailPriority.High; // enumeration oMail2.Body = sBody; System.Web.Mail.SmtpMail.SmtpServer = SERVER2; System.Web.Mail.SmtpMail.Send(oMail2); oMail2 = null; }
/// <summary> /// 在Send()方法有问题时,用这个方法替换 /// </summary> public void SendWebMail() { System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); mail.From = From; mail.To = String.Join(";", To.Replace(',', ';').Split(';')); mail.Body = Body; mail.Cc = CC; mail.Subject = Subject; mail.Priority = System.Web.Mail.MailPriority.High; mail.BodyFormat = System.Web.Mail.MailFormat.Html; mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", Port); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", UserName); mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); if (Files != null) { foreach (string file in Files) { MailAttachment MyAttachment = new MailAttachment(file); mail.Attachments.Add(MyAttachment); } } System.Web.Mail.SmtpMail.SmtpServer = Server; try { System.Web.Mail.SmtpMail.Send(mail); } catch (Exception ex) { ErrorMessage = ex.GetType().Name + ":" + ex.Message; } }
internal virtual void SendMessage(MailMessage message) { lock (emailLock) { SmtpMail.SmtpServer = configurationData.SmtpServer; SmtpMail.Send(message); } }
public AbstractEmailSender() { this.mail = new System.Net.Mail.MailMessage(); this.mail.IsBodyHtml = false; this.mail.BodyEncoding = System.Text.Encoding.UTF8; this.mail.Priority = System.Net.Mail.MailPriority.Normal; this.mailClient = new SmtpClient(); this.mailQQ = new System.Web.Mail.MailMessage(); }
/// <summary>Envia um mail</summary> public static bool Send( string to, string subject, string body ) { MailMessage message = new MailMessage(); message.To = to; message.Subject = subject; message.Body = body; return Send(message); }
public static void Main(string[] args) { if (args.Length < 5 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help"))) { Console.WriteLine(usage); } else { try { string server = args[0]; string to = args[1]; string from = args[2]; string subject = args[3]; string body = args[4]; string[] attachments = null; if (args.Length > 5) { attachments = new string[args.Length - 5]; for (int i = 0; i < attachments.Length; i++) { attachments[i] = args[5 + i]; } } MailMessage myMail = new MailMessage(); myMail.To = to; myMail.From = from; myMail.Subject = subject; myMail.Body = body; if (attachments != null) { foreach (string file in attachments) { if (File.Exists(file)) { string filePath = Path.GetFullPath(file); myMail.Attachments.Add(new MailAttachment(filePath, MailEncoding.Base64)); } else throw new Exception("File "+file+" cannot be attached"); } } SmtpMail.SmtpServer = server; SmtpMail.Send(myMail); } catch(Exception e) { Console.WriteLine(e.Message); return; } Console.WriteLine("Message has been sent"); } }
public virtual void NotifyAdmin(string msg) { MailMessage mail = new MailMessage(); mail.From = from; mail.To = admin; mail.Subject = msg; mail.Body = msg; SmtpMail.Send(mail); }
public virtual void NotifyUser(string user, string msg) { MailMessage mail = new MailMessage(); mail.From = from; mail.To = user; mail.Subject = msg; mail.Body = msg; SmtpMail.Send(mail); }
public MailImages (IBrowsableCollection collection) { message = new MailMessage (); message.From = "*****@*****.**"; message.To = "*****@*****.**"; message.Subject = "test"; EsmtpMail mail = new EsmtpMail ("smtp.gmail.com", "lewing", "ricedream"); mail.Send (message) }
public virtual void Send(string from, string to, string subject, string messageText) { MailMessage mailMessage = new MailMessage(); mailMessage.From = from; mailMessage.To = to; mailMessage.Subject = subject; mailMessage.BodyFormat = MailFormat.Html; mailMessage.Body = messageText; SmtpMail.Send(mailMessage); }
public void SendMessage(Guid messageId, string recipientEmail, string subject, string text) { var myMail = new MailMessage { From = _from.ToString(), To = recipientEmail, Subject = subject, BodyFormat = MailFormat.Html, Body = text, Headers = { { Constants.MessageIdHeader, messageId.ToString() } } }; myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", _host); if (_port.HasValue) { myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", _port); } myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); //sendusing: cdoSendUsingPort, value 2, for sending the message using //the network. //smtpauthenticate: Specifies the mechanism used when authenticating //to an SMTP //service over the network. Possible values are: //- cdoAnonymous, value 0. Do not authenticate. //- cdoBasic, value 1. Use basic clear-text authentication. //When using this option you have to provide the user name and password //through the sendusername and sendpassword fields. //- cdoNTLM, value 2. The current process security context is used to // authenticate with the service. myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _userName); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _password); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); var portPart = _port.HasValue ? (":" + _port.Value) : string.Empty; SmtpMail.SmtpServer = _host + portPart; try { var task = Task.Run(() => SmtpMail.Send(myMail)); const int Timeout = 10000; if (!task.Wait(Timeout)) { throw new WebException("Task timeout", WebExceptionStatus.Timeout); } } catch (Exception ex) { Loggers.MainLogger.Error(ex); throw Error.NotAvailableExceptionCreator.UnknownSmtpError(); } }
private void SendDeniedEmail() { Lead oLead = (Lead)Session["s_oLead"]; const string SERVER = "relay-hosting.secureserver.net"; MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = "*****@*****.**"; oMail.To = oLead.Email; oMail.Subject = "Status Update: Your VIPCashFast Application"; oMail.BodyFormat = MailFormat.Html; // enumeration oMail.Priority = MailPriority.High; // enumeration oMail.Body = "Dear " + oLead.first_name + ",<br /><br />We apologize that we are unable to find your short term cash advance at this time.<br /><br />"; oMail.Body = oMail.Body + "We work hard to make it easy for you to receive cash in your account by continuing to improve our VIP application system and expanding our network of lenders.<br /><br />"; oMail.Body = oMail.Body + "A couple of important points,<br /><br />"; oMail.Body = oMail.Body + "1. Throughout the week different lenders enter and exit our VIP network dependent on their cash credit funding capabilities. In the long run this lender flexibility improves approval rates. However, you may have received a denied application due to unfortunate lender timing.<br /><br />"; oMail.Body = oMail.Body + "2. Please remember our VIP service is FREE and you can reapply at your convenience, visit <a href=\"http://vipcashfast.com/?ls=DE\" >vipcashfast.com</a> 24/7!<br /><br />"; oMail.Body = oMail.Body + "Additionally, please consider the following VIP alternative financial resources,<br /><br />"; //if (oLead.is_military == 1) //{ // oMail.Body = oMail.Body + "<a href=\"http://www.credit.com/r2/loans/af=p76544&c=140737-3e3d163c75\">PioneerMilitaryLoans.com</a><br /><br />"; //} oMail.Body = oMail.Body + "<a href=\"http://www.sastrk.com/z/5525/CD5193/&dp=289412\">FiscalPayday.com</a><br /><br />"; oMail.Body = oMail.Body + "<a href=\"http://www.sastrk.com/z/5313/CD5193/&dp=289414\">PacificPayDay.com</a><br /><br />"; oMail.Body = oMail.Body + "<a href=\"http://www.sastrk.com/z/8739/CD5193/&dp=289411\">FirstLibertyLendingNetwork.com</a><br /><br />"; //PROBLEM WITH LEADPILE LINKS //oMail.Body = oMail.Body + "<a href=" + UrlEncode("http://www.uscashwire.com/?affp=l4ZmsX") + ">USCashWire.com</a><br /><br />"; //oMail.Body = oMail.Body + "<a href=\"http://www.uscashwire.com/?affp=l4ZmsX\">USCashWire.com</a><br /><br />"; //oMail.Body = oMail.Body + "<a href=\"http://www.paydaycashstart.com/?affp=l4ZmsX\">PayDayCashStart.com</a><br /><br />"; //oMail.Body = oMail.Body + "<a href=\"http://www.jdoqocy.com/ia66lnwtnvAEJIKFDDACBIHKGDI\">DiscountAdvances.com</a><br /><br/>"; oMail.Body = oMail.Body + "These resources will submit your application to lender networks outside our VIP system.<br /><br/>Sincerely,<br />Customer Service Team<br /><a href=\"http://vipcashfast.com/?ls=DE\" >vipcashfast.com</a>"; //oMail.Body = "test"; SmtpMail.SmtpServer = SERVER; SmtpMail.Send(oMail); oLead = null; oMail = null; // free up resources }
public void SendEmail() { MailMessage myMail = new MailMessage(); myMail.From = "*****@*****.**"; myMail.To = "*****@*****.**"; myMail.Subject = "UtilMailMessage001"; myMail.Priority = MailPriority.Normal; myMail.BodyFormat = MailFormat.Html; myMail.Body = "<html><body>UtilMailMessage001 - success</body></html>"; SmtpMail.Send(myMail); }
public void Send (MailMessage message) { EsmtpClient smtp = new EsmtpClient (smtpServer, username, password, use_ssl); // wrap the MailMessage in a MailMessage wrapper for easier // access to properties and to add some functionality MailMessageWrapper messageWrapper = new MailMessageWrapper( message ); smtp.Send (messageWrapper); smtp.Close (); }
public ActionResult Contact(ContactEmailModels e) { string ValidationMessage = String.Empty; ViewBag.Name = String.Empty; ViewBag.Email = String.Empty; ViewBag.Phone = String.Empty; ViewBag.Message = String.Empty; if (!String.IsNullOrEmpty(e.Name) && !String.IsNullOrEmpty(e.Message) && !String.IsNullOrEmpty(e.Phone) && !String.IsNullOrEmpty(e.Email)) { var emailmessage = new System.Web.Mail.MailMessage() { Subject = e.Name, Body = "From: " + e.Name + "\n Phone Number: " + e.Phone + "\n Job Description: " + e.Message + "\n Email: " + e.Email, From = "*****@*****.**", To = "*****@*****.**", BodyFormat = MailFormat.Text, Priority = System.Web.Mail.MailPriority.High }; var passWord = "******"; var email = new MailAddress("*****@*****.**", "Jeff"); var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(email.Address, passWord) }; using (var mess = new System.Net.Mail.MailMessage(email, email) { Subject = e.Name, Body = "From: " + e.Name + "\n Phone Number: " + e.Phone + "\n Job Description: " + e.Message + "\n Email: " + e.Email }) { smtp.Send(mess); } //System.Web.Mail.SmtpMail.SmtpServer = "relay-hosting.secureserver.net"; //SmtpMail.Send(emailmessage); MessageBox("Email sent successfully!"); //return RedirectToAction("Index", "Home", null); } return(View(e)); }
/// <summary> /// Send an email. /// </summary> /// <param name="to"></param> /// <param name="from"></param> /// <param name="subject"></param> /// <param name="body"></param> public static void Send(string to, string from, string subject, string body) { MailMessage message = new MailMessage(); message.From = from; message.To = to; message.Subject = subject; message.BodyFormat = MailFormat.Text; message.Body = body; SmtpMail.SmtpServer = Config.GetConfiguration()["SMTPServer"]; SmtpMail.Send(message); }
/// <summary> /// 发送不带附件的Email /// </summary> /// <param name="content">Email的内容</param> private static void SendEmailWithoutAccessories(string content) { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); message.BodyFormat = System.Web.Mail.MailFormat.Html; message.From = Configuration.EventLogAddresser; message.To = Configuration.EventLogAddressee; message.Cc = ""; message.Bcc = ""; message.Subject = "系统日志定期扫描报告"; message.Body = content; System.Web.Mail.SmtpMail.Send(message); }
/// <summary> /// 寄發信件 /// </summary> /// <param name="strTo">收件者</param> /// <param name="strSubject">主旨</param> /// <param name="strBody">信件內容</param> /// <param name="strFile">附件實體路徑</param> /// <returns></returns> public static bool SendMailSSL(string strTo, string strSubject, string strBody, string[] strFile) { bool bRet = false; try { const string SMTP_SERVER = "http://schemas.microsoft.com/cdo/configuration/smtpserver"; const string SMTP_SERVER_PORT = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"; const string SEND_USING = "http://schemas.microsoft.com/cdo/configuration/sendusing"; const string SMTP_USE_SSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl"; const string SMTP_AUTHENTICATE = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"; const string SEND_USERNAME = "******"; const string SEND_PASSWORD = "******"; string mailServer = ConfigurationManager.AppSettings["mailServer"].ToString(); string UserName = ConfigurationManager.AppSettings["UserName"].ToString(); string Pw = ConfigurationManager.AppSettings["Password"].ToString(); string mailFrom = ConfigurationManager.AppSettings["mailFrom"].ToString(); string mailBCC = ConfigurationManager.AppSettings["mailFromCC"].ToString(); System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage(); mail.Fields[SMTP_SERVER] = mailServer; mail.Fields[SMTP_SERVER_PORT] = 465; mail.Fields[SEND_USING] = 2; mail.Fields[SMTP_USE_SSL] = true; mail.Fields[SMTP_AUTHENTICATE] = 1; mail.Fields[SEND_USERNAME] = UserName; mail.Fields[SEND_PASSWORD] = Pw; mail.Subject = strSubject; mail.Body = strBody; for (int i = 0; i < strFile.Length; i++) { if (System.IO.File.Exists(strFile[i])) { mail.Attachments.Add(new System.Web.Mail.MailAttachment(strFile[i])); } } mail.BodyFormat = System.Web.Mail.MailFormat.Html; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.Bcc = mailBCC; mail.From = mailFrom; mail.To = strTo; System.Web.Mail.SmtpMail.Send(mail); bRet = true; } catch (Exception ex) { bRet = false; } return(bRet); }
protected void BtnSaveEditted_Click(object sender, EventArgs e) { if (TxtDefectName.Text == string.Empty || DDLStatus1.SelectedIndex == -1 || DDlAssignedto.SelectedIndex == -1 || DDlCycle.SelectedIndex == -1 || DdlProject.SelectedIndex == -1 || DDlTester.SelectedIndex == -1 || TxtTcAssociated.Text == string.Empty || DDlModule.SelectedIndex == -1 || txtComments.Text == string.Empty) { lbMessage.Visible = true; lbMessage.Text = "Please enter data in all the fields"; } else { defectid1 = Convert.ToInt32(this.Session["DefectID11"].ToString()); DateTime Systimestamp = DateTime.Now; string LoginUser = Session["New"].ToString(); string defectname = TxtDefectName.Text; string status = DDLStatus1.SelectedValue.ToString(); string date1 = txtDate.Text.ToString(); DateTime date = Convert.ToDateTime(date1); int histid = dbObj.GetHistoryid(defectid1); string Comments = txtComments.Text; DateTime Sysdate1 = DateTime.Now; TxtLastupdated.Text = Sysdate1.ToString(); string item = DDLStatus1.SelectedItem.ToString(); //defectid = dbObj.GetNextDefectID(); // DateTime date = Convert.ToDateTime (txtDate.Text); string filenames = ""; string filesize = ""; Byte Attachments = 0;; //AtC:\Documents and Settings\z123993\my documents\Downloads\Framework-4-0\FreeTextBox.dlltachments = 0; //Attachments = null; //dbObj.UpdateDefect(Comments, LoginUser, defectid1, defectname, date, status, DDlCycle.SelectedValue, TxtDescription.Text, DdlProject.SelectedValue, DDlTester.SelectedValue, TxtTcAssociated.Text, DDlModule.SelectedValue, DDlAssignedto.SelectedValue, Sysdate1, filenames, filesize, Attachments, histid); // llbMessage.Visible = true; lbMessage.Text = "Defect Added Succesfully"; System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); message.From = "*****@*****.**"; message.To = "*****@*****.**"; message.Subject = "Defect Number:-" + TxtDefectID.Text + ""; message.Body = "Defect Editted and Saved "; SmtpClient client = new SmtpClient(); //client.SendCompleted += new SendCompletedEventHandler(); System.Web.Mail.SmtpMail.SmtpServer = "azshspp04.caremarkrx.net"; System.Web.Mail.SmtpMail.Send(message); Server.Transfer("HomePage.aspx", true); } }
public static void sendmail(string mbody) { const string SERVER = "relay-hosting.secureserver.net"; MailMessage oMail = new System.Web.Mail.MailMessage(); oMail.From = "*****@*****.**"; oMail.To = "*****@*****.**"; //oMail.To = "[email protected],[email protected],[email protected],[email protected]"; oMail.Subject = "Form 2013 Annual Registration Submit on the web site"; oMail.BodyFormat = MailFormat.Html; // enumeration oMail.Priority = MailPriority.High; // enumeration oMail.Body = "Sent at: " + DateTime.Now + mbody; SmtpMail.SmtpServer = SERVER; //string mes = string.Empty; //string sTo = "[email protected],[email protected],[email protected]"; //string sFrom = "*****@*****.**"; //string sSubject = "Contactus from Medical Summit"; //string sBody = mbody.Trim(); //string sMailServer = "127.0.0.1"; //MailMessage MyMail = new MailMessage(); //MyMail.From = sFrom; //MyMail.To = sTo; ////MyMail.Cc //MyMail.Subject = sSubject; //MyMail.Body = sBody; //MyMail.BodyEncoding = System.Text.Encoding.UTF8; //MyMail.BodyFormat = MailFormat.Html; //SmtpMail.SmtpServer = sMailServer; try { SmtpMail.Send(oMail); oMail = null; // free up resources //mes += " Trying to send e-mail."; //SmtpMail.Send(MyMail); //MyMail = null; //mes += " The message was sent to " + MyMail.To; //mes += " "; //Response.Redirect(host_url); //MakeMessage(true, mes); } catch (Exception ex) { //mes += " " + ex.Message; //mes += " The tests failed."; //MakeMessage(false, mes); //Response.Redirect(host_url); } }
public static bool SendEmail(string pGmailEmail, string pGmailPassword, string pTo, string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath) { try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", pGmailEmail); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pGmailPassword); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = pGmailEmail; myMail.To = pTo; myMail.Subject = pSubject; myMail.BodyFormat = pFormat; myMail.Body = pBody; if (pAttachmentPath.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(pAttachmentPath); myMail.Attachments.Add(MyAttachment); myMail.Priority = System.Web.Mail.MailPriority.High; } System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"; System.Web.Mail.SmtpMail.Send(myMail); return(true); } catch (Exception ex) { //throw; return(true); } }
public static bool Send( MailMessage message ) { try { SmtpMail.Send( message ); } catch { return false; } return true; }
public static bool SendEmail(string Email, string Password, string pTo, string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath) { try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.office365.com"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "110"); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "587"); //sendusing: cdoSendUsingPort, value 2, for sending the message using //the network. //smtpauthenticate: Specifies the mechanism used when authenticating //to an SMTP //service over the network. Possible values are: //- cdoAnonymous, value 0. Do not authenticate. //- cdoBasic, value 1. Use basic clear-text authentication. //When using this option you have to provide the user name and password //through the sendusername and sendpassword fields. //- cdoNTLM, value 2. The current process security context is used to // authenticate with the service. myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Email); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = Email; myMail.To = pTo; myMail.Subject = pSubject; myMail.BodyFormat = pFormat; myMail.Body = pBody; if (pAttachmentPath.Trim() != "") { try { MailAttachment MyAttachment = new MailAttachment(pAttachmentPath); myMail.Attachments.Add(MyAttachment); myMail.Priority = System.Web.Mail.MailPriority.High; } catch { } } System.Web.Mail.SmtpMail.SmtpServer = "smtp.office365.com:110"; // System.Web.Mail.SmtpMail.Send(myMail); return(true); } catch (Exception ex) { throw; } }
/// <summary> /// 发送带附件的Email /// </summary> /// <param name="accessories">附件文件的物理地址</param> private static void SendEmailWithAccessories(string accessories, string content) { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); System.Web.Mail.MailAttachment attachment = new System.Web.Mail.MailAttachment(accessories); //定义一个附件 message.Attachments.Add(attachment); message.BodyFormat = System.Web.Mail.MailFormat.Html; message.From = Configuration.EventLogAddresser; message.To = Configuration.EventLogAddressee; message.Cc = ""; message.Bcc = ""; message.Subject = "系统日志定期扫描报告"; message.Body = content; System.Web.Mail.SmtpMail.Send(message); }
public void SendMail() { string subject = "测试邮件"; string body = "测试内容"; string from = "*****@*****.**"; string to = "*****@*****.**"; string userName = "******"; string password = "******"; string smtpServer = "smtp.exmail.qq.com"; string port = "465"; bool ssl = true; System.Web.Mail.MailMessage mmsg = new System.Web.Mail.MailMessage(); //邮件主题 mmsg.Subject = subject; mmsg.BodyFormat = MailFormat.Html; //邮件正文 mmsg.Body = body; //正文编码 mmsg.BodyEncoding = System.Text.Encoding.UTF8; //优先级 mmsg.Priority = MailPriority.Normal; //发件者邮箱地址 mmsg.From = from; //收件人收箱地址 mmsg.To = to; mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //用户名 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName); //密码 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password); //端口 mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port); //是否ssl mmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", ssl ? "true" : "false"); //Smtp服务器 System.Web.Mail.SmtpMail.SmtpServer = smtpServer; try { SmtpMail.Send(mmsg); Console.WriteLine("发送成功"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("发送失败,失败原因:" + ex.Message); } }
public bool SendMail(List<string> mailIds, string subject, string body, List<string> attachmentFilePaths) { try { var myMailMessage = new MailMessage(); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", PGmailAccount); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", PGmailPassword); myMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMailMessage.From = PGmailAccount; if (mailIds != null && mailIds.Count > 0) { string toMails = mailIds.Aggregate(string.Empty, (current, mailid) => current + (mailid + ";")); toMails = toMails.Substring(0, toMails.Length - 1); myMailMessage.To = toMails; myMailMessage.Subject = subject; var pFormat = new MailFormat(); pFormat = MailFormat.Html; myMailMessage.BodyFormat = pFormat; myMailMessage.Body = body; //string pAttachmentPath = "//servername/filename"; //contains the path of the attachment (if any) //if (pAttachmentPath.Trim() != "") //{ // MailAttachment MyEmailAttachment = new MailAttachment(pAttachmentPath); // myMailMessage.Attachments.Add(MyEmailAttachment); // myMailMessage.Priority = MailPriority.High; //} if (attachmentFilePaths != null && attachmentFilePaths.Count > 0) { foreach (string attachmentFilePath in attachmentFilePaths) { var attachment = new MailAttachment(attachmentFilePath); myMailMessage.Attachments.Add(attachment); } } myMailMessage.Priority = MailPriority.High; SmtpMail.SmtpServer = "smtp.gmail.com:465"; SmtpMail.Send(myMailMessage); } return true; } catch (Exception) { return false; } }
static void mail (string recipient, string body) { MailMessage m = new MailMessage (); m.From = "*****@*****.**"; m.To = recipient; m.Subject = "Your Monodoc passkey"; m.Body = String.Format ("\n\nWelcome to the Mono Documentation Effort,\n\n" + "This is your passkey for contributing to the Mono Documentation effort:\n " + " {0}\n\n" + "The Mono Documentation Team ([email protected])", body); SmtpMail.SmtpServer = "localhost"; SmtpMail.Send (m); }
public void SendEmail(IEnumerable<string> to, IEnumerable<string> cc, IEnumerable<string> bcc, string subject, string body, bool isHtml) { var host = _config.AppSettings.GetValue<string>("SmtpHost"); var user = _config.AppSettings.GetValue<string>("SmtpUserName"); var password = _config.AppSettings.GetValue<string>("SmtpPassword"); var port = _config.AppSettings.GetValue<int>("SmtpPort"); var from = _config.AppSettings.GetValue<string>("SmtpFrom"); var toString = to.Where(t => t.IsNotEmpty()).Join(";"); var ccString = string.Empty; if (cc != null && cc.Any()) { ccString = cc.Where(t => t.IsNotEmpty()).Join(";"); } var bccString = string.Empty; if (bcc != null && bcc.Any()) { bccString = bcc.Where(t => t.IsNotEmpty()).Join(";"); } //used System.Web.Mail instead of system.net.mail because of operation timeout // using System.Web.Mail; var emailMessage = new MailMessage(); emailMessage.BodyFormat = isHtml ? MailFormat.Html : MailFormat.Text; emailMessage.Subject = subject; emailMessage.Body = body; emailMessage.From = from; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = host; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = port; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = user; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = password; emailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = true; emailMessage.To = toString; if (!ccString.IsEmpty()) { emailMessage.Cc = ccString; } if (!bccString.IsEmpty()) { emailMessage.Bcc = bccString; } SmtpMail.SmtpServer = host; SmtpMail.Send(emailMessage); }
/// <summary> /// /// </summary> /// <param name="To"></param> /// <param name="CC"></param> /// <param name="BCC"></param> /// <param name="TemplateID"></param> /// <param name="Subject"></param> /// <param name="loginID"></param> public void SendMail(string To, string CC, string BCC, string TemplateID, string Subject, string loginID, string systemName, string customerNumber, string adminName) { try { string From = GetFromAddress(TemplateID); // // Variable Declarations // string _bodyMessage = GetContent(TemplateID); _bodyMessage = _bodyMessage.Replace("[Vendor]", adminName); _bodyMessage = _bodyMessage.Replace("[LoginID]", loginID); _bodyMessage = _bodyMessage.Replace("[Customer]", "<font color='#000066'>PFC Customer #: </font>" + customerNumber); _bodyMessage = _bodyMessage.Replace("[UserType]", systemName); // // Create a Mail Message object // System.Web.Mail.MailMessage EmailMessage = new System.Web.Mail.MailMessage(); SmtpMail.SmtpServer = smtpServer; // // Assigning To,From,CC address to mail // EmailMessage.To = To; EmailMessage.From = From; EmailMessage.Cc = CC; EmailMessage.BodyFormat = MailFormat.Html; // // Subject line of the Email // EmailMessage.Subject = Subject; // // Body of the Email // EmailMessage.Body = _bodyMessage; // // Send the message // System.Web.Mail.SmtpMail.Send(EmailMessage); } catch (Exception ex) { string a = ex.Message; } }
public bool SendEmail(string pGmailEmail, string pGmailPassword, string pTo, string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath) { try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com"); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465"); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", pGmailEmail); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", pGmailPassword); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = pGmailEmail; myMail.To = pTo; myMail.Subject = pSubject; myMail.BodyFormat = pFormat; myMail.Body = pBody; myMail.BodyEncoding = System.Text.Encoding.UTF8; if (pAttachmentPath.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(pAttachmentPath); myMail.Attachments.Add(MyAttachment); myMail.Priority = System.Web.Mail.MailPriority.High; } System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"; System.Web.Mail.SmtpMail.Send(myMail); return true; } catch (Exception ex) { throw; } }
private void btnSend_ServerClick(object sender, EventArgs e) { if (txtFrom.Text == string.Empty) { lblErr.Visible = true; lblErr.Text = "Error: Please enter your email address."; } else { BECustomers ds = new BECustomers(); BPCustomers bp = new BPCustomers(); ds = bp.SelectByCustomerEmail(txtFrom.Text); if (ds.tbl_Customers.Count > 0) { BESetup setupInfo = new BESetup(); BPSetup bpSetup = new BPSetup(); setupInfo = bpSetup.SelectAll(); SmtpMail.SmtpServer = setupInfo.tbl_Setup[0].SetupEmailServer; BECustomers.tbl_CustomersRow customer = ds.tbl_Customers[0]; MailMessage mm = new MailMessage(); mm.To = (txtFrom.Text.Replace(",", ";")).Trim(); mm.From = setupInfo.tbl_Setup[0].SetupEmailAddress1; //mm.Subject = txtSubj.Text; mm.Subject = "Carrie'l Salon and Spa Administration"; mm.Body += "Thank you for using Carrie'l Salon and Spa's Password Retrieval System."; mm.Body += "\r\n\r\nHere is your information:"; mm.Body += "\r\n\r\nEmail:\t" + customer.CustomerEmail; mm.Body += "\r\nPassword:\t" + customer.CustomerPassword; mm.Body += "\r\n\r\nhttp://www.Carriel.ca"; try { SmtpMail.Send(mm); } catch{} lblErr.Visible = true; lblErr.Text = "Your password has been sent."; pnlEmail.Visible = false; btnCont.Visible = true; } else { lblErr.Visible = true; lblErr.Text = "Error: Sorry, we could not find that email address."; } } }
public static bool SendEmail(string pTo, string pSubject, string pBody) { string pGmailEmail = "*****@*****.**"; string pGmailPassword = "******"; string smtpServer = "smtp.gmail.com"; string smtpServerPort = "465"; System.Web.Mail.MailFormat pFormat = System.Web.Mail.MailFormat.Html; string pAttachmentPath = string.Empty; System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", smtpServerPort); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", "2"); //sendusing: cdoSendUsingPort, value 2, for sending the message using //the network. //smtpauthenticate: Specifies the mechanism used when authenticating //to an SMTP //service over the network. Possible values are: //- cdoAnonymous, value 0. Do not authenticate. //- cdoBasic, value 1. Use basic clear-text authentication. //When using this option you have to provide the user name and password //through the sendusername and sendpassword fields. //- cdoNTLM, value 2. The current process security context is used to // authenticate with the service. myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //Use 0 for anonymous myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", pGmailEmail); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", pGmailPassword); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = pGmailEmail; myMail.To = pTo; myMail.Subject = pSubject; myMail.BodyFormat = pFormat; myMail.Body = pBody; if (pAttachmentPath.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(pAttachmentPath); myMail.Attachments.Add(MyAttachment); myMail.Priority = System.Web.Mail.MailPriority.High; } System.Web.Mail.SmtpMail.Send(myMail); return(true); }
private void btnForgotpass_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if (Page.IsValid) { if (this.emailNotification) { BLUser wUser = new BLUser(); wUser.EMail = txtEMail.Text.Trim().ToLower(); wUser.Retrieve(); if (wUser.ID>0 && wUser.Enabled) { StringWriter writer = new StringWriter(); Server.Execute("email/emailForgotPass.aspx?email="+wUser.EMail, writer); string strhtmlbody = writer.ToString(); // Response.Write(strhtmlbody); // Response.End(); MailMessage objMailMessage = new MailMessage(); objMailMessage.Subject = siteName+": your password"; objMailMessage.From = this.emailNotificationCustomerFrom; objMailMessage.To = wUser.EMail; objMailMessage.Cc = this.emailNotificationCustomerCc; objMailMessage.Bcc = this.emailNotificationCustomerBcc; objMailMessage.Body = strhtmlbody; objMailMessage.BodyFormat = MailFormat.Html; SmtpMail.SmtpServer = this.smtpServer; SmtpMail.Send( objMailMessage ); } } Response.Redirect(".?page=login"); } }