Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Mass Emailer in C# question

I was in the process of building one for myself,l but I wasnt sure which way I should proceed.
Here are the options:
1.
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.To.Add(Iterate thru all the emails and add them);
smtp.Send(); // send the emails all at once.
or
2.
Loop it like this
Add an email address, then send the email
Add an email address, then send the email
Which one would be better to use?
I doubt you're going to have SO many it would matter, but if you threaded it, it would go faster, in which you would add e-mail then send back and fourth.
Okay, thanks I guess I will look into this.
1. I actually have quite a bit from days of harvesting.
2. Im not very good with threading, can you maybe provide a tad bit of help, or links?
I didn't work with the SMTP classes but if you can use an SmtpClient and login with different accounts of course that is more efficient. Because constructing a new instance for one account over and over again is more expensive then using the same instance but with different accounts.

For threading I recommend 'studying' the TPL (Task Parallel Library). Its the most efficient to use ;) Example:
Code
var task = new Task(() =>
{
var smtpClient = new SmtpClient();
foreach (var account in Accounts)
{
smtpClient.Login(account.User, account.Pass);
smtpClient.Send(message, title); //just random code :P
}
});
task.Start();
:O Whoa, thanks!
Ill really be able to use this!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by edgareatisMay 23, 2015 06:31 PM 2 421 May 23, 2015 06:31 PM
Last Post: edgareatis
[.NET] by ThePsychoCoderApr 10, 2014 10:38 AM 8 311 Apr 10, 2014 10:38 AM
Last Post: K-On!
[Shell] by .Hack//Dec 15, 2013 07:23 AM 1 135 Dec 15, 2013 07:23 AM
Last Post: SIM-1073426