Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
public ActionResult Index(MyMailModel objModelMail, string submit)
        {            
            if (submit == "Productscar")
            {

                string from1 = "mandla.anilbabu@gmail.com";
                string email1 = objModelMail.Email;
               
               
                using (MailMessage mail = new MailMessage("mandla.anilbabu@gmail.com",from1))
                {

                    mail.Subject = "This is subject new cars theam";
                   
                    mail.Body = "New cars Theam 1 selected" + Environment.NewLine + "FROM    :" + email1;
                   
                    mail.IsBodyHtml = false;
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.gmail.com";
                    smtp.EnableSsl = true;
                    NetworkCredential networkCredential = new NetworkCredential(from1, "PWD");
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = networkCredential;
                    smtp.Port = 587;                  
                    smtp.Send(mail);
                    ViewBag.Message = "Sent";
                    ViewData["Message"] = "Saved theam successfully,this will update soon...";
                    return View("Index", objModelMail);

                }
            }
}


Model:

C#
public class MyMailModel
    {
        public string From { get; set; }
        [Required(ErrorMessage = "Please enter your email address")]
        [RegularExpression(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}", ErrorMessage = "Please enter correct email")]
        public string Email { get; set; }       

        public string To { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
    }
Posted
Updated 29-Jul-15 4:41am
v2
Comments
Sergey Alexandrovich Kryukov 29-Jul-15 10:38am    
What's wrong with reading original MSDN documentation?
—SA

As you can see, the property System.Net.Mail.MailMessage.To is a collection. So, if you can have one element in the collection, you can have any number of them, each representing different e-mail address:
https://msdn.microsoft.com/en-us/library/94z1w6d7%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.net.mail.mailaddresscollection(v=vs.110).aspx[^].

—SA
 
Share this answer
 
easy try this..

C#
foreach (var address in addresses.Split(new [] {";"}, StringSplitOptions.RemoveEmptyEntries))
{
    mailMessage.To.Add(address);
}
 
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