Hi, I need to send lots of emails(probably hundreds a day) on schedule base. The way I'm thinking to do it is as follows but the problem is that my Body field can get very big, and if i add it as string it gets ugly.
SmtpClient client = new SmtpClient(); //host and port picked from web.config
client.EnableSsl = true;
MailMessage message = new MailMessage();
message.Body = "test from winservice"; // HERE IS MY PROBLEM
message.IsBodyHtml = true;
message.From = new MailAddress("[email protected]");
message.Subject = "My subject";
message.To.Add(new MailAddress("[email protected]"));
try
{
client.Send(message);
}
catch (Exception)
{
}
When i had to do it from aspx page i used
MailDefinition message = new MailDefinition();
message.BodyFileName = @"~\EmailTemplate\Template1.htm";
ListDictionary replacements = new ListDictionary();
replacements.Add("<% Name %>", this.txtName.Text);
replacements.Add("<% PhoneOrEmail %>", this.txtPhoneOrEmail.Text);
replacements.Add("<% Message %>", this.txtMessage.Text);
MailMessage msgHtml = message.CreateMailMessage(RECIPIENTS, replacements, new LiteralControl());
I think it is elegant solution but i don't want to reference to System.Web.UI.WebControls.MailDefinition because i'm in winservice.
My questions are:
- What is the best way to send bulk emails from winservice?
- Is it posible to send it from gmail account? or they are going to block me after a while?
thanks for any help.