Reputation: 49
Hello i have a problem with sendig mails from asp.net web site. Here is my code
private void mailgonder(string mail, string adsoyad)
{
MailMessage mm = new MailMessage();
mm.From = new MailAddress("my mail address", "my name");
mm.Subject = "YENİ DUYURU";
mm.Body = "Sistemde okumadığınız yeni bir duyuru bulunmaktadır.";
mm.To.Add(new MailAddress(mail, adsoyad));
SmtpClient sc = new SmtpClient("my smtp client");
sc.Port = 587;
sc.Credentials = new NetworkCredential("my username", "my password");
sc.Send(mm);
}
I want to send mail to 1500 users with same time. How can i do this in asp.net (we will have over 1000 member in this web project)
I can send like this to one person. But i don't know how can i send this to multiple persons
Thanks
Upvotes: 0
Views: 1325
Reputation: 1560
I Believe the simplest approach by far is to make a contact group. Doing this will keep the amount of code written to a minimum. Here is a link explaining how to do so in Outlook How to make a contact group
Once you have the contact group setup, simply do this:
String Devemail = "[email protected]";
MailMessage message = new MailMessage();
message.To.Add(Devemail);
//The rest of your code here
The rest of your code will work fine. If someone has a better/simpler approach, please feel free to correct me.
EDIT: I am kind of shocked that we recommend he hard code 1500 email addresses into his code. Can someone give me a good reason for using that approach over using an email group?
Upvotes: 0
Reputation: 11317
As MailMessage.To
is a collection, you can add as much as you want :
mm.To.Add(new MailAddress("[email protected]", "user1"));
mm.To.Add(new MailAddress("[email protected]", "user2"));
mm.To.Add(new MailAddress("[email protected]", "user3"));
mm.To.Add(new MailAddress("[email protected]", "user4"));
.....
until
mm.To.Add(new MailAddress("[email protected]", "user1499"));
mm.To.Add(new MailAddress("[email protected]", "user1500"));
NOTE : Restrictions may exist according to your mail server or access provider. For more efficiency, use a mailing list.
Upvotes: 2
Reputation: 320
You have to send each user seperate emails. Do not, never, add more than 1 address to TO unless you have sender score certification, doing opposite will cause you get banned from mail providers since they would think you are a spammer. And also spam list is global, which means if you get banned from gmail, you will also get banned from hotmail or yahoo in a short period of time.
Just select for example 20 email addresses from database each time and loop that 20 and call your mailgonder method for each.
Other than what I wrote above, if you write multiple TO's, each of your users will see each others email adressses which is not cool from user perspective.
Upvotes: 0