Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Hello,
i want to sent mails in group by using comma(,) as separator for each E-mail Id's and when button is clicked the mail should be sent
as a group mail.


can u please Help 

Posted
Updated 16-Dec-11 1:47am
v3

 
Share this answer
 
Comments
RaviRanjanKr 16-Dec-11 15:21pm    
My 5+
 
Share this answer
 
Comments
RaviRanjanKr 16-Dec-11 15:22pm    
My 5!
P.Salini 17-Dec-11 4:16am    
Thanks Ranjan
If you actually mean that you want to send an email toa group of people, all you have to do is add the appropriate number of email addresses to the To property (keeping in mind that all of the recipients will see all of the other recipients' email addresses):

C#
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("person1@whocares.com");
message.To.Add("person2@whocares.com");
message.To.Add("person3@whocares.com");


If you want to send more than one email to a single person, you can either merge the bodies of the emails, or send an indvidual email for each "body" that you have.
 
Share this answer
 
v2
try this code

public static void SendMail(string Subject, string Body, bool IsHtml, string From, string To, string Cc, string Bcc)
{
    const char SEPARATOR = ',';
    string[] Tos = new string[0];
    string[] Ccs = new string[0];
    string[] Bccs = new string[0];

    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress(From);
    mailMessage.Subject = Subject;
    mailMessage.Body = Body;
    mailMessage.IsBodyHtml = IsHtml;
    if (!String.IsNullOrEmpty(To))
         Tos = To.Split(new char[] { SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
    if (!String.IsNullOrEmpty(Cc))
         Ccs = Cc.Split(new char[] { SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
    if (!string.IsNullOrEmpty(Bcc))
        Bccs = Bcc.Split(new char[] { SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
    foreach (var item in Tos)
    {
        mailMessage.To.Add(new MailAddress(item));
    }
    foreach (string item in Ccs)
    {
        if (!isMailCointained(item, Tos))
        {
            mailMessage.CC.Add(new MailAddress(item));
        }   
    }
    foreach (string item in Bccs)
    {
        if (!isMailCointained(item, Tos) && !isMailCointained(item ,Ccs))
        {
            mailMessage.Bcc.Add(new MailAddress(item));
        }
    }
    try
    {
        SmtpClient smtpClient = new SmtpClient();
        // add your smtp server!
        smtpClient.Host = ConfigurationManager.AppSettings["YOUR EMAIL SERVER"];
        smtpClient.Send(mailMessage); 
 }
     catch(Exception exc){// add your exception handlers.. }
}
private static bool isMailCointained(string mail, string[] mails)
{
    bool toRet = false;
    foreach (var item in mails)
    {
        if (mail == item)
            return true;
    }
    return toRet;
}


If you call the SendMail method using:
SendMail("Hello", "<h3>Hello from myrocode!</h3>", true,
               "myEmail@a.com", "a@a.com,b@a.com,c@a.com", "z@a.com,b@a.com", "x@a.com,y@a.com,z@a.com");

You email will be deliverd with the following headers:
To: a@a.com
b@a.com
c@a.com
Cc:z@a.com
Bcc:x@a.com
y@a.com
 
Share this answer
 
v2
Hi,

if you add each recipient in BCC(Blank carbon copy) then mail will be send as individual.

thanks
-amit.
 
Share this answer
 
 
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