Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m not able to send bulk emails together,still i am not using foreach loop or other Loop.
Please suggest me is it possible to send bulk emails alltogether or not ,Need to use foreach loop

i am only able to send LIKE THIS...........
C#
MailMessage mailMessage = new MailMessage();
               SmtpClient smtpClient = new SmtpClient();
               foreach (string EmailID in EmailAddress)
               {


                       mailMessage = new MailMessage(FormEmailAddress, EmailID, Subject, MailMessage);

                       smtpClient = new SmtpClient();
                       mailMessage.IsBodyHtml = false;
                       smtpClient.UseDefaultCredentials = true;

                       smtpClient.Credentials = new System.Net.NetworkCredential(FormEmailAddress, Password);

                   try
                   {
                       smtpClient.Send(mailMessage);

                   }
                   catch
                   {

                   }
                   finally
                   {
                       mailMessage = null;
                       smtpClient = null;
                   }
                   }
Posted
Updated 19-Sep-12 19:38pm
v2
Comments
_Kapil 20-Sep-12 1:57am    
Thanks for this solution,but i am looking for send mails in bulk so that other recipients don't have information to whom i send this emails.

I hope you understand what i am looking for..........

Try this link if you want to another approach to send bulk emails.

Automated-Email-Notifications-using-SQL-Server-Job-Schedular

manage-bulk-emails-aspnet
 
Share this answer
 
v2
If the content is same then why are you going for sending it n+1 times ?
You could simply add To address from your for loop.
C#
MailMessage mailMessage = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
foreach (string EmailID in EmailAddress)
{
mailMessage.Bcc.Add(EmailID); /// see Bcc here
}
mailMessage.Subject = Subject;
mailMessage.From = new MailAddress(FormEmailAddress);
mailMessage.Body = mailMessage;
smtpClient = new SmtpClient();
mailMessage.IsBodyHtml = false;//upto you
smtpClient.UseDefaultCredentials = true; // required ?????
 
smtpClient.Credentials = new System.Net.NetworkCredential(FormEmailAddress, Password); 

try
{
smtpClient.Send(mailMessage);

}
catch
{

}
finally
{
mailMessage = null;
smtpClient = null;
}
 
Share this answer
 
v3
Comments
Venkatesh Mookkan 20-Sep-12 1:50am    
I don't think, this is a right solution.

Adding all the emailed into the MailMessage.From would expose the email ids to the other users too. If this is an application like sending newsletters to people, I would not do that. May be Bcc, would be the right choice.
Sushil Mate 20-Sep-12 1:52am    
if you want to hide the individual's Email address from other, Add the receivers as a Bcc (blind carbon copy/copies circulating) address instead of a To address.
Kuthuparakkal 20-Sep-12 1:58am    
I am trying to present an idea/logic. And it's commonsense to use BCC or what.
_Kapil 20-Sep-12 2:16am    
i am agree with you , but i am looking to send bulk eamils in BCC so please suggest me...
Thanks
_Kapil 20-Sep-12 2:05am    
i want to send Bulk Mails in BCC but not to send it only send mail at first address...

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