Click here to Skip to main content
15,868,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am usign this code to send mails on setting of my company domain, it's working perfectly but problem is that when i mention multiple recipients in TO, CC field then it sends OK but when i check inbox and check TO, FROM then first recipient appears many times and other recipients don't appear in CC, To field.

e.g. i send mails TO: user@yahoo.com; fatman@gmail.com; groomed@ymail.com with CC: hh@ymail.com; jesse@ugnada.com.uk

then it deliver mails to all TO and CC recipients but in inbox when i check email then above CC, TO appears like this:

TO: user@yahoo.com;; user@yahoo.com; user@yahoo.com

CC: hh@ymail.com;; hh@ymail.com;; hh@ymail.com;

why ?

code:

C#
SmtpClient SmtpServer = new SmtpClient("mail.precisetech.com.pk");
                var mail = new MailMessage();
                mail.From = new MailAddress("hunain@precisetech.com.pk");

                string[] to = txtEmailTo.Split(';');
                foreach (string mailTo in to)
                {
                    mail.To.Add(txtEmailTo);
                }

                string[] cc = txtCC.Split(';');
                foreach (string copyTo in cc) 
                {
                    MailAddress cCopy = new MailAddress(txtCC);
                    mail.CC.Add(cCopy);
                } 
                mail.Subject = txtSubject;
                mail.IsBodyHtml = true;
               // mail.CC = txtCC;
                string htmlBody;
                htmlBody = txtBody;
                mail.Body = txtBody;
                SmtpServer.Port = 25;
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials = new System.Net.NetworkCredential("hunain@precisetech.com.pk","");
                SmtpServer.EnableSsl = false;
               
			
	
	     try {
                SmtpServer.Send(mail);
                ViewBag.Confirmation = "Daily Log Has Been Submitted";
                return View();
             }
         
         catch (Exception ex) 
             {
               ViewBag.Confirmation = ex.Message;
               return View();
  	         }
Posted

1 solution

No need to add the cc or bcc address each time. you can add the all addresses at a time by passing the string with seperated by comma(,).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900