public bool EnviarEmail(string De, string Para, string Copia, string Asunto, System.Web.Mail.MailFormat Formato, string CuerpoEmail, string ServidorSMTP) { bool auxiliar = false; int compAdjuntar; //int compPara; MailMessage mail = new MailMessage(); mail.From = De; mail.To = Para; mail.Cc = Copia; mail.Subject = Asunto; mail.BodyFormat = Formato; mail.Body = CuerpoEmail; SmtpMail.SmtpServer.Insert(0, ServidorSMTP); try { SmtpMail.Send(mail); auxiliar = true; } catch (Exception ex) { //LOG auxiliar = false; strCodError1 = ex.Message; //objTextFile.EscribirLog(" ---> ERROR -- ENVIANDO EMAIL. CODIGO: " + strCodError1); } return(auxiliar); }
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); }
public static int Send(Common.Web.Core oDB, string mTo, string mFrom, string mSubject, string mBody, int sentBy, System.Web.Mail.MailFormat mBodyFormat) { bool bSent = false; try { MailMessage msg = new MailMessage(); msg.To = mTo; msg.From = mFrom; msg.Subject = mSubject; msg.Body = mBody; msg.BodyFormat = mBodyFormat; try { SmtpMail.SmtpServer = Config.GetDbConfigValue(oDB, Config.DBConfig.SMTPServer); SmtpMail.Send(msg); } catch (System.Web.HttpException ehttp) { Log.Write("SmtpMail", ehttp); return(1); } bSent = true; int ID = oDB.ExecuteReturnInt("admSaveSentEmail", new object[] { "@DateSent", DateTime.Now, "@Subject", mSubject, "@SentTo", mTo, "@SentFrom", mFrom, "@Message", mBody, "@EmailSentByID", sentBy }); if (ID <= 0) { return(2); } else { return(0); } } catch (Exception exception) { Log.Write("SmtpMail", exception); return(bSent?2:1); } }
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; } }
public static void SendEmail(string smtpServer, string to, string from, string subject, string msg, System.Web.Mail.MailFormat format) { SendEmail(smtpServer, to, from, string.Empty, string.Empty, subject, msg, format, null); }
public static void SendEmail(string smtpServer, string to, string from, string cc, string cco, string subject, string msg, System.Web.Mail.MailFormat format, string[] filesToAttach) { MailMessage msgMail = new MailMessage(); msgMail.To = to; msgMail.Cc = cc; msgMail.Bcc = cco; msgMail.From = from; msgMail.Subject = subject; msgMail.Body = msg; msgMail.BodyFormat = format; SmtpMail.SmtpServer = smtpServer; if (filesToAttach != null) { string file = string.Empty; for (int i = 0; i < filesToAttach.Length; i++) { file = filesToAttach[i] as String; msgMail.Attachments.Add(new MailAttachment(file, System.Web.Mail.MailEncoding.Base64)); } } try { SmtpMail.Send(msgMail); } catch { // catch code here } }
public static bool SendEmail( string pTo, string ccEmails, string pSubject, string pBody, System.Web.Mail.MailFormat pFormat, string pAttachmentPath) { if (pTo.Contains("mawarid") || ccEmails.Contains("mawarid")) { return(false); } //string Mail = System.Configuration.ConfigurationManager.AppSettings["CSEmail"]; //string MailPass = System.Configuration.ConfigurationManager.AppSettings["CSPassword"]; string exchangeDomain = System.Configuration.ConfigurationManager.AppSettings["ExchangeDomain"]; // pTo = "*****@*****.**"; //ccEmails = "*****@*****.**"; try { System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage(); NetworkCredential credential = new NetworkCredential(Mail, MailPass, SMTPServer); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpserver", SMTPServer); 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", Mail); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", MailPass); myMail.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = Mail; pTo = pTo.Replace(",", ";"); pTo = pTo.Replace(",", ";"); myMail.To = pTo; myMail.Cc = ccEmails; 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 = SMTPServer + ":587"; System.Web.Mail.SmtpMail.Send(myMail); return(true); } catch (Exception ex) { throw; } }
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 int Send(Common.Web.Core oDB, string mTo, string mFrom, string mSubject, string mBody, System.Web.Mail.MailFormat mBodyFormat) { return(Send(oDB, mTo, mFrom, mSubject, mBody, 1, mBodyFormat)); }
private bool WsSendSimpleEmail(string subject, string message, string emailAddress, List<string> attachmentPaths, Guid currentUserId) { try { System.Web.Mail.MailFormat format = new System.Web.Mail.MailFormat(); string FromEmail = "*****@*****.**"; string Password = "******"; 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", FromEmail); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = FromEmail; myMail.Subject = subject; myMail.BodyFormat = format; myMail.Body = message; foreach (string path in attachmentPaths) { if (path.Trim() != "") { MailAttachment MyAttachment = new MailAttachment(path); myMail.Attachments.Add(MyAttachment); } } System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465"; myMail.To = emailAddress; System.Web.Mail.SmtpMail.Send(myMail); } catch (Exception ex) { throw; } return true; }
private bool SendToUsers(List<User> recipients, string subject, string message, List<string> attachmentPaths) { System.Web.Mail.MailFormat format = new System.Web.Mail.MailFormat(); string FromEmail = "*****@*****.**"; string Password = "******"; //string FromEmail = "*****@*****.**"; //string Password = "******"; 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"); //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", FromEmail); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Password); myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); myMail.From = FromEmail; myMail.Subject = subject; myMail.BodyFormat = format; myMail.Body = message; //System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage("*****@*****.**", "*****@*****.**"); //MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**"); MemoryStream stream = new MemoryStream(new byte[64000]); // System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(stream, attachmentPaths[0]); //myMail.Attachments.Add(attachment); //myMail.Body = "This is an async test."; //System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com 465"); //smtp.Credentials = new NetworkCredential("login", "password"); System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com 465"; foreach (var user in recipients) { //myMail.To = user.EmailAddress; System.Web.Mail.SmtpMail.Send(myMail); } //if (attachmentPaths != null && attachmentPaths.Count > 0 && attachmentPaths[0] != null) //{ // foreach (string path in attachmentPaths) // { // if (path.Trim() != "") // { // MailAttachment MyAttachment = new MailAttachment(path); // myMail.Attachments.Add(MyAttachment); // } // } //} //System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com 465"; //foreach (var user in recipients) //{ // myMail.To = user.EmailAddress; // System.Web.Mail.SmtpMail.Send(myMail); //} return true; } catch (Exception ex) { throw; } return true; }