.Net System.Mail.Message adding multiple “To” addresses

前端 未结 8 1367
悲&欢浪女
悲&欢浪女 2020-12-30 18:56

EDIT: This question is pointless, except as an exercise in red herrings. The issue turned out to be a combination of my idiocy (NO ONE was being emailed as the hos

相关标签:
8条回答
  • 2020-12-30 19:45

    Put in addresses this code:

    objMessage.To.Add(***addresses:=***"email1@yahoo.com , email2@aol.com , email3@gmail.com")

    0 讨论(0)
  • 2020-12-30 19:45
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net.Mail;
    using System.Web;
    
    namespace HMS.HtmlHelper
    {
        public class SendmailHelper
        {
            //Created SendEMail method for sendiing mails to users 
            public bool SendEMail(string FromName, string ToAddress, string Subject, string Message)
            {
                bool valid =false;
                try
                {
                    string smtpUserName = System.Configuration.ConfigurationManager.AppSettings["smtpusername"].ToString();
                    string smtpPassword = System.Configuration.ConfigurationManager.AppSettings["smtppassword"].ToString();
                    MailMessage mail = new MailMessage();``
                    mail.From = new MailAddress(smtpUserName, FromName);
                    mail.Subject = Subject;
                    mail.To.Add(FormatMultipleEmailAddresses(ToAddress));
                    //mail.To.Add(ToAddress);
                    mail.Body = Message.ToString();
                    mail.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["smtpserverport"]);
                    smtp.Host = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"]; /
                    smtp.Credentials = new System.Net.NetworkCredential(smtpUserName, smtpPassword);
                    smtp.EnableSsl = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["ssl"]); ;
                    smtp.Send(mail);
                    valid = true;
    
                }
                catch (Exception ex)
                {
                    valid =false ;
                }
    
                return valid;
            }
    
    
    
            public string FormatMultipleEmailAddresses(string emailAddresses)
            {
                var delimiters = new[] { ',', ';' };
    
                var addresses = emailAddresses.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
    
                return string.Join(",", addresses);
            }
    
        }
    }``
    
    0 讨论(0)
提交回复
热议问题