protected bool SendMail(MailMessage mm) { SmtpSection section = (SmtpSection)WebConfigurationManager.GetSection("system.net/mailSettings/smtp"); SmtpClient client = new SmtpClient(section.Network.Host, section.Network.Port); return(client.Send(mm, section.Network.UserName, section.Network.Password)); }
public static void SendConfirmationEmailAR(User user) { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); string companyEmail = section.Network.UserName; string companyPassword = section.Network.Password; user.EmailConfirmed = false; MailMessage m = new MailMessage(companyEmail, user.Email); m.Subject = "تأكيد"; m.Body = string.Format("أهلًا" + " {0}" + "<BR/>" + " شكرًا لتسجيلك, من فضلك اضغط على الرابط لنأكيد بريدك الالكتروني واكمال تسجيلك" + "<BR/><a href =\"{1}\" title =\"تأكيد البريد الالكتروني\">{1}</a>", user.FirstNameAR, user.URL.URL1); m.IsBodyHtml = true; SmtpClient smcl = new SmtpClient(); smcl.Host = section.Network.Host; smcl.Port = section.Network.Port; smcl.Credentials = new NetworkCredential(companyEmail, companyPassword); smcl.EnableSsl = true; smcl.Send(m); }
public static void EnviarMensagemContato(String nome, String email, String titulo, String mensagem) { try { // Envio da mensagem do usuário ao e-mail do administrador do sistema: SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); String msg = String.Format( "A aplicação registrou um novo contato!" + Environment.NewLine + Environment.NewLine + "****************************************************************************************************" + Environment.NewLine + "Nome do usuário: " + nome + Environment.NewLine + "E-mail de contato: " + email + Environment.NewLine + "Título da mensagem: " + titulo + Environment.NewLine + "Mensagem enviada: " + Environment.NewLine + mensagem + Environment.NewLine + "****************************************************************************************************" ); EnviarEmail(section.Network.UserName, "Novo Contato DOMINUS: " + titulo, msg); // Envio de confirmacao do contato ao e-mail fornecido pelo usuário: msg = String.Format( "Olá, " + nome + "!" + Environment.NewLine + Environment.NewLine + "A equipe Dominus registrou o seu contato e o retornaremos assim que possível." + Environment.NewLine + Environment.NewLine + "****************************************************************************************************" + Environment.NewLine + "Título da mensagem: " + titulo + Environment.NewLine + "Mensagem enviada: " + Environment.NewLine + mensagem + Environment.NewLine + "****************************************************************************************************" + Environment.NewLine + Environment.NewLine + "Este é um envio automático de e-mail. Não é necessário respondê-lo" ); EnviarEmail(email, "Recebemos sua mensagem!", msg); } catch (Exception ex) { throw ex; } }
public static bool SendEmail(List <MailAddress> receivers, string subject, string body, bool isBodyHtml) { try { SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(smtpSection.From); foreach (MailAddress receiver in receivers) { mailMessage.To.Add(receiver); } mailMessage.Subject = subject; mailMessage.Body = body; mailMessage.IsBodyHtml = isBodyHtml; SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); return(true); } catch { return(false); } }
public async Task <IHttpActionResult> GetToSendBulkMail([FromUri] string passcode) { SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); if (passcode != smtpSection.Network.Password) { return(BadRequest()); } object retresult = await datacontext.SelectAllPendingPrimaryEvidence(); if (retresult.GetType().ToString() != "System.String") { List <Personnel_with_pending_primary_evidence> list = (List <Personnel_with_pending_primary_evidence>)retresult; foreach (Personnel_with_pending_primary_evidence item in list) { //send mail! object sendresult = await MailingUtils.sendNotificationAllPendingPrimaryEvidence(item); while (sendresult != null) { //send again if fail sendresult = await MailingUtils.sendNotificationAllPendingPrimaryEvidence(item); } } return(Ok()); } else { return(InternalServerError(new Exception(retresult.ToString()))); } }
public bool SendEmail(string ToAddress, string name, string generatedPassword, string fileName) { bool isSuccess = false; string mailBody = File.ReadAllText(fileName); SmtpSection smtpObj = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); using (MailMessage mm = new MailMessage()) { mm.From = new MailAddress(smtpObj.From); // Email address of the sender mm.To.Add(ToAddress); // Email address of the recipient. mm.Subject = "Credentails for logging into the ECare System"; mailBody = mailBody.Replace("{Name}", name); mailBody = mailBody.Replace("{email}", ToAddress); mailBody = mailBody.Replace("{password}", generatedPassword); mm.Body = mailBody; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = smtpObj.Network.Host; smtp.EnableSsl = smtpObj.Network.EnableSsl; smtp.UseDefaultCredentials = true; NetworkCredential NetworkCred = new NetworkCredential(smtpObj.Network.UserName, smtpObj.Network.Password); smtp.UseDefaultCredentials = smtpObj.Network.DefaultCredentials; smtp.Credentials = NetworkCred; smtp.Port = smtpObj.Network.Port; smtp.Send(mm); } return(isSuccess); }
/// <summary> /// Enviar Email SMS /// </summary> /// <param name="to">Message to address</param> /// /// <param name="cc">Message to address</param> /// <param name="body">Text of message to send</param> /// <param name="subject">Subject line of message</param> public void EnviaEmail(string to, string msg, string subjectNumeroCel) { try { //obtem os valores smtp do arquivo de configuração . Não vou usar estes valores estou apenas mostrando como obtê-los SmtpSection mailSettings = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); if (mailSettings != null) { SmtpClient smtp = new SmtpClient(); MailMessage mail = new MailMessage(); mail.Body = msg; mail.IsBodyHtml = false; mail.To.Add(new MailAddress(to)); mail.From = new MailAddress(mailSettings.Network.UserName, "Economiza Já", Encoding.UTF8); mail.Subject = subjectNumeroCel; mail.SubjectEncoding = Encoding.UTF8; mail.Priority = MailPriority.Normal; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(mailSettings.Network.UserName, mailSettings.Network.Password); smtp.Host = mailSettings.Network.Host; smtp.Port = mailSettings.Network.Port; smtp.EnableSsl = false; smtp.Send(mail); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public CustomSmtpClient(string sectionName) { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("mailSettings/" + sectionName); _smtpClient = new SmtpClient(); if (section != null) { _smtpClient.DeliveryMethod = section.DeliveryMethod; if (section.DeliveryMethod == SmtpDeliveryMethod.Network) { _smtpClient.Host = section.Network.Host; _smtpClient.Port = section.Network.Port; _smtpClient.UseDefaultCredentials = section.Network.DefaultCredentials; _smtpClient.Credentials = new NetworkCredential(section.Network.UserName, section.Network.Password, section.Network.ClientDomain); _smtpClient.EnableSsl = section.Network.EnableSsl; if (section.Network.TargetName != null) { _smtpClient.TargetName = section.Network.TargetName; } } if (section.SpecifiedPickupDirectory != null && section.SpecifiedPickupDirectory.PickupDirectoryLocation != null) { _smtpClient.PickupDirectoryLocation = section.SpecifiedPickupDirectory.PickupDirectoryLocation; } } }
public static bool Send(string to, string subject, string body) { string from = string.Empty; string localIP = "http://zimops/ZWFM/UserLogin"; //string publicIp = "http://197.211.216.65/ZWFM/UserLogin.aspx"; SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); try { using (SmtpClient client = new SmtpClient(section.Network.Host, section.Network.Port)) { client.EnableSsl = section.Network.EnableSsl; client.Timeout = 2000000; client.Credentials = new System.Net.NetworkCredential(section.Network.UserName, section.Network.Password); client.Send(section.From, to, subject, body + " Click here: " + localIP); client.Dispose(); } } catch (Exception ex) { return(false); } return(false); }
public void EnviarEmail(string assunto, string corpo, List <string> lstEmailDestino) { SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; MailMessage email = new MailMessage(); lstEmailDestino.ForEach(emailDestino => { email.To.Add(new MailAddress(emailDestino)); }); email.From = new MailAddress("*****@*****.**", "One Sistema"); email.Subject = assunto; email.Body = corpo; email.Priority = MailPriority.High; email.IsBodyHtml = false; SmtpClient client = new SmtpClient(); client.Host = smtpSection.Network.Host; client.Port = smtpSection.Network.Port; client.EnableSsl = smtpSection.Network.EnableSsl; client.UseDefaultCredentials = smtpSection.Network.DefaultCredentials; client.Credentials = new NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password); try { client.Send(email); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void SendMail(string Subject = "SMARTRECRUITER DEMO - MAIL SUBJECT", string Body = "DEMO - MAIL BODY", List <string> ToMails = null) { try { if (ToMails.Count > 0) { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); SmtpClient client = new SmtpClient(); client.Host = section.Network.Host; client.Port = section.Network.Port; client.UseDefaultCredentials = false; client.EnableSsl = section.Network.EnableSsl; client.Credentials = new System.Net.NetworkCredential(section.Network.UserName, section.Network.Password); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(section.Network.UserName); foreach (var mail in ToMails) { mailMessage.To.Add(mail); } mailMessage.Subject = Subject; mailMessage.Body = Body; mailMessage.IsBodyHtml = true; client.Send(mailMessage); } } catch (Exception ex) { } }
public async Task SendAsync(Message msg) { try { SmtpSection smtp = null; if (String.IsNullOrWhiteSpace(msg.From)) { smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; msg.From = smtp.From; } MailMessage mail = new MailMessage(); mail.To.Add(msg.Destination); mail.From = new MailAddress(msg.From); mail.BodyEncoding = System.Text.Encoding.UTF8; mail.Body = msg.Body; mail.Subject = msg.Subject; mail.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(); smtpClient.UseDefaultCredentials = smtp.Network.DefaultCredentials; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.Port = smtp.Network.Port; smtpClient.EnableSsl = smtp.Network.EnableSsl; smtpClient.Credentials = new System.Net.NetworkCredential(smtp.Network.UserName, smtp.Network.Password); await smtpClient.SendMailAsync(mail); } catch (Exception exe) { throw exe; } }
public void Mail(string fromName, string toName, string toAddress, string subject, string body, bool isHtml = false, string[] fileAttachmentPaths = null) { SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); if (smtpSection != null) { MailAddress from = new MailAddress(smtpSection.From, fromName); MailAddress to = new MailAddress(toAddress, toName); MailMessage message = new MailMessage(from, to); message.Subject = subject; message.Body = body; message.IsBodyHtml = isHtml; if (fileAttachmentPaths != null) { foreach (string fileAttachmentPath in fileAttachmentPaths) { Attachment attach = new Attachment(fileAttachmentPath); message.Attachments.Add(attach); } } bool enableSsl = smtpSection.Network.EnableSsl; string host = smtpSection.Network.Host; string password = smtpSection.Network.Password; int port = smtpSection.Network.Port; string userName = smtpSection.Network.UserName; Mail(message, host, port, userName, password, false, enableSsl); } }
private void SendMail() { try { SmtpSection smtpSec = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; var fromAddress = smtpSec.Network.UserName; var toAddress = "*****@*****.**"; string fromPassword = smtpSec.Network.Password; string subject = "Test"; string body = "Mail"; var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = smtpSec.Network.Host; smtp.Port = smtpSec.Network.Port; smtp.EnableSsl = smtpSec.Network.EnableSsl; // smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); //smtp.Timeout = 20000; } MailMessage mailMessage = new MailMessage("*****@*****.**", toAddress); mailMessage.Body = body; mailMessage.Subject = subject; mailMessage.IsBodyHtml = true; smtp.Send(mailMessage); } catch (Exception e) { // return 1; } }
public static EmailConnectionInfo GetEmailConnectionInfo(SmtpSection smtpSection, string subject, string fromEmail, string toEmail) { Contract.Requires(smtpSection != null); Contract.Requires(smtpSection.Network != null); Contract.Requires(string.IsNullOrWhiteSpace(subject) == false); Contract.Requires(string.IsNullOrWhiteSpace(toEmail) == false); Contract.Ensures(Contract.Result <EmailConnectionInfo>() != null); var info = new EmailConnectionInfo { Port = smtpSection.Network.Port, MailServer = smtpSection.Network.Host, FromEmail = fromEmail, EnableSsl = smtpSection.Network.EnableSsl, EmailSubject = subject, ToEmail = toEmail }; if (smtpSection.Network.DefaultCredentials == false) { info.NetworkCredentials = new NetworkCredential(smtpSection.Network.UserName, smtpSection.Network.Password); } return(info); }
private static bool SendEmail(List <string> strMailUsers, string subject, string messageTxt, string replyMail) { string strMailBody = GuiLanguage.GetGuiLanguage("Templates").GetString("EmailRecommendation"); SmtpSection smtpSec = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MailMessage objMail = new MailMessage { From = new MailAddress(smtpSec.From), Subject = subject, Body = messageTxt, IsBodyHtml = true }; foreach (string strMailTo in strMailUsers) { if (!string.IsNullOrEmpty(strMailTo)) { objMail.To.Add(new MailAddress(strMailTo)); } } if (!string.IsNullOrEmpty(replyMail)) { objMail.ReplyTo = new MailAddress(replyMail); } SmtpClient objSmtp = new SmtpClient(); objSmtp.Send(objMail); return(true); }
/// <summary> /// 连接到邮件服务器 /// </summary> private static void ConnectServer() { if (mail == null) { try { SmtpSection cfg = ConfigurationManager.GetSection(@"system.net/mailSettings/smtp") as SmtpSection; SmtpNetworkElement SmtpConfig = cfg.Network; mail = new MailMessage { From = new MailAddress(cfg.From) }; smtp = new SmtpClient { Host = SmtpConfig.Host, Port = Convert.ToInt32(SmtpConfig.Port), DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(SmtpConfig.UserName, SmtpConfig.Password) }; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } }
private void txtRead_Click(object sender, EventArgs e) { // System.Configuration MySection1 mySectioin1 = (MySection1)SAPGlobalSettings.config.GetSection("MySection111"); //MySection1 mySectioin1 = (MySection1)System.Configuration.ConfigurationManager.GetSection("MySection111"); txtUsername1.Text = mySectioin1.UserName; txtUrl1.Text = mySectioin1.Url; // MySection2 mySectioin2 = (MySection2)System.Configuration.ConfigurationManager.GetSection("MySection222"); MySection2 mySectioin2 = (MySection2)SAPGlobalSettings.config.GetSection("MySection222"); txtUsername2.Text = mySectioin2.Users.UserName; txtUrl2.Text = mySectioin2.Users.Password; // MySection3 mySection3 = (MySection3)System.Configuration.ConfigurationManager.GetSection("MySection333"); MySection3 mySection3 = (MySection3)SAPGlobalSettings.config.GetSection("MySection333"); txtCommand1.Text = mySection3.Command1.CommandText.Trim(); txtCommand2.Text = mySection3.Command2.CommandText.Trim(); XmlKeyValueSection mySection4 = (XmlKeyValueSection)System.Configuration.ConfigurationManager.GetSection("MySection444"); txtKeyValues.Text = string.Join("\r\n", (from kv in mySection4.KeyValues.Cast <XmlKeyValueSetting>() let s = string.Format("{0}={1}", kv.Key, kv.Value) select s).ToArray()); SmtpSection section = System.Configuration.ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; labMailFrom.Text = "Mail From: " + section.From; }
public static bool SendEmails(string from, string to, string subject, string body) { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); try { using (SmtpClient client = new SmtpClient(section.Network.Host, section.Network.Port)) { client.EnableSsl = section.Network.EnableSsl; client.Timeout = 2000000; client.Credentials = new System.Net.NetworkCredential(section.Network.UserName, section.Network.Password); if (from != "") { client.Send(from, to, subject, body); } else { client.Send(section.From, to, subject, body); } client.Dispose(); } } catch (Exception ex) { return(false); } return(false); }
/// <summary> /// To get appropriate SmtpSection for mail sending /// </summary> /// <param name="isSupportMail"></param> /// <returns>SmtpSection</returns> public static SmtpSection GetSmtpSection() { SmtpSection smtpSection = new SmtpSection(); smtpSection = (SmtpSection)ConfigurationManager.GetSection("mailSettings/smtp_other"); return(smtpSection); }
/// <summary> /// 发送邮件 /// </summary> /// <param name="SmtpSection">配置信息</param> /// <param name="userMail">要发送到的邮箱地址</param> /// <param name="message">邮件内容</param> /// <returns></returns> public void SendEmail(SmtpSection smtpSec, string userMail, string message) { // SmtpSection smtpSec = NetSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~/web.config")).MailSettings.Smtp; string tomailhost = userMail.Split('@')[1]; // smtpSec.From = "*****@*****.**";// MailInfo.mailaddr; // smtpSec.Network.Host = "smtp.sina.com";// MailInfo.mailhost; // smtpSec.Network.UserName = "******";//MailInfo.mailaddr; // smtpSec.Network.Password = "******";//MailInfo.mailpwd; MailMessage m_message = new MailMessage(); m_message.From = new MailAddress("*****@*****.**", "sesameregister"); m_message.To.Add(new MailAddress(userMail)); m_message.Subject = "UTH"; m_message.SubjectEncoding = System.Text.Encoding.UTF8; m_message.Body = message; m_message.IsBodyHtml = true; SmtpClient m_smtpClient = new SmtpClient("smtp.sina.com", 25); //SmtpClient m_smtpClient = new SmtpClient(); //if (MailInfo.IsSSL) // m_smtpClient.EnableSsl = true; //注意这一句,gmail这样的需要允许SSL的邮箱必须要,否则会报错 m_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; m_smtpClient.Credentials = new System.Net.NetworkCredential(smtpSec.Network.UserName, smtpSec.Network.Password); m_smtpClient.Send(m_message); }
public virtual ActionResult Emails(SmtpSection model) { var config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); var settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings"); if (settings != null) { if (model.DeliveryMethod == SmtpDeliveryMethod.Network) { settings.Smtp.DeliveryMethod = SmtpDeliveryMethod.Network; settings.Smtp.Network.ClientDomain = model.Network.ClientDomain; settings.Smtp.Network.DefaultCredentials = model.Network.DefaultCredentials; settings.Smtp.Network.EnableSsl = model.Network.EnableSsl; settings.Smtp.Network.Host = model.Network.Host; settings.Smtp.Network.Password = model.Network.Password; settings.Smtp.Network.Port = model.Network.Port; settings.Smtp.Network.UserName = model.Network.UserName; } else if (model.DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory) { settings.Smtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; settings.Smtp.SpecifiedPickupDirectory.PickupDirectoryLocation = model.SpecifiedPickupDirectory.PickupDirectoryLocation; } } config.Save(); return(View(model)); }
private void SendMail(string fromName, string toName, string toEmail, string subject, string mailBody) { try { mailBody = mailBody.Replace("<%SITE_URL%>", SiteContext.SiteURL); mailBody = mailBody.Replace("<%TO_USERNAME%>", toName); mailBody = mailBody.Replace("<%FROM_USERNAME%>", fromName); try { SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(smtpSection.From, SiteContext.SiteName); mailMessage.To.Add(new MailAddress(toEmail)); mailMessage.Subject = subject; mailMessage.Body = mailBody; mailMessage.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); } catch { } } catch { } }
public virtual MvcMailMessage SendEmailOrderChange(string emailTo, int orderId, string orderStatus) { ViewData.Model = new Tuple <int, string>(orderId, orderStatus); SmtpSection section = (SmtpSection)System.Configuration.ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MvcMailMessage mailMessage = this.Populate(x => { x.ViewName = "EmailOrderChange"; x.From = new MailAddress(section.From, this.FromDisplayName); x.To.Add(emailTo); x.Subject = String.Concat(this.FromDisplayName, " - статус заказа изменен"); x.BodyEncoding = Encoding.UTF8; x.SubjectEncoding = Encoding.UTF8; x.BodyTransferEncoding = System.Net.Mime.TransferEncoding.Base64; }); Dictionary <string, string> resources = this.CreateMailResources(mailMessage, "EmailOrderChange"); this.PopulateBody(mailMessage, "EmailOrderChange", resources); Mailer.AdjustMessageEncoding(mailMessage); return(mailMessage); }
public void Send(Message msg) { if (String.IsNullOrWhiteSpace(msg.From)) { SmtpSection smtp = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection; msg.From = smtp.From; } using (SmtpClient smtp = new SmtpClient()) { smtp.Timeout = 5000; try { MailMessage mailMessage = new MailMessage(msg.From, msg.To, msg.Subject, msg.Body) { IsBodyHtml = sendAsHtml }; smtp.Send(mailMessage); } catch (SmtpException e) { Tracing.Error("[SmtpMessageDelivery.Send] SmtpException: " + e.Message); } catch (Exception e) { Tracing.Error("[SmtpMessageDelivery.Send] Exception: " + e.Message); } } }
public virtual MvcMailMessage SendEmailVerification(string emailTo, Guid token) { ViewData.Model = token.ToString(); SmtpSection section = (SmtpSection)System.Configuration.ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MvcMailMessage mailMessage = this.Populate(x => { x.ViewName = "EmailVerification"; x.From = new MailAddress(section.From, this.FromDisplayName); x.To.Add(emailTo); x.Subject = String.Concat(this.FromDisplayName, " - подтверждение email"); x.BodyEncoding = Encoding.UTF8; x.SubjectEncoding = Encoding.UTF8; x.BodyTransferEncoding = System.Net.Mime.TransferEncoding.Base64; }); Dictionary <string, string> resources = this.CreateMailResources(mailMessage, "EmailVerification"); this.PopulateBody(mailMessage, "EmailVerification", resources); Mailer.AdjustMessageEncoding(mailMessage); return(mailMessage); }
public static void SendResetPasswordEmailAR(User user) { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); string companyEmail = section.Network.UserName; string companyPassword = section.Network.Password; MailMessage m = new MailMessage(companyEmail, user.Email); m.Subject = "إعادة ضبط كلمة المرور"; m.Body = string.Format("أهلًا" + " {0}" + "<BR/>" + "لقد طلبت إعادة ضبط كلمة مرورك, من فضلك اضغط على الرابط لإعادة الضبط" + "<BR/><a href =\"{1}\" title =\"إعادة ضبط كلمة مرور المستخدم\">{1}</a>" + "<BR/>" + "إذا لم تقم بهذا الطلب فيمكنك تجاهل هذه الرسالة.", user.FirstNameAR, user.URL.URL1); m.IsBodyHtml = true; SmtpClient smcl = new SmtpClient(); smcl.Host = section.Network.Host; smcl.Port = section.Network.Port; smcl.Credentials = new NetworkCredential(companyEmail, companyPassword); smcl.EnableSsl = true; smcl.Send(m); }
private MailMessage PopulateMailObject(EmailQueueViewModel viewModel, SmtpSection smtpSection) { MailMessage eMailMessage = new MailMessage(); eMailMessage.From = new MailAddress(smtpSection.Network.UserName); eMailMessage.ReplyToList.Add(smtpSection.Network.UserName); eMailMessage.To.Add(viewModel.ToEmailId); eMailMessage.Subject = viewModel.EmailSubject; eMailMessage.IsBodyHtml = true; eMailMessage.Body = viewModel.MessageBody; eMailMessage.Priority = MailPriority.High; if (!String.IsNullOrEmpty(viewModel.AttachedFiles)) { var files = viewModel.AttachedFiles.Split(',').ToList(); foreach (string fileName in files) { if (!string.IsNullOrEmpty(fileName)) { var fileFullPath = AppProperties.BasePhysicalPath + AppConstants.GenerateFileAt + fileName; if (File.Exists(fileFullPath)) { var attachmentItem = new Attachment(fileFullPath); eMailMessage.Attachments.Add(attachmentItem); } } } } return(eMailMessage); }
public static void EnviarEmail(String email, String titulo, String mensagem) { try { MailMessage mailMessage = new MailMessage { Subject = titulo, Body = mensagem }; mailMessage.To.Add(email); SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); using (SmtpClient client = new SmtpClient(section.Network.Host, section.Network.Port)) { client.UseDefaultCredentials = section.Network.DefaultCredentials; client.Credentials = new NetworkCredential(section.Network.UserName, section.Network.Password); client.EnableSsl = section.Network.EnableSsl; client.Send(mailMessage); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool SendMail(MailViewModel viewmodel) { try { SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); var message = new MailMessage(); message.From = new MailAddress(section.From, viewmodel.MailName); message.To.Add(new MailAddress(section.Network.UserName)); message.Subject = viewmodel.MailSubject; message.Body = viewmodel.MailBody; using (var client = new SmtpClient()) { client.EnableSsl = section.Network.EnableSsl; client.UseDefaultCredentials = section.Network.DefaultCredentials; client.Credentials = new NetworkCredential(section.Network.UserName, section.Network.Password); client.Host = section.Network.Host; client.Port = section.Network.Port; client.Send(message); client.Dispose(); } } catch (Exception ex) { throw ex; } return(result); }