|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using NewsletterService.Classes;
namespace NewsletterService
{
class Program
{
private static DataTable MemberTable = new DataTable();
private static string subject = "";
protected static string body = "";
protected static string smtp = "";
protected static string senderEmail = "";
protected static bool sendViaSql = false;
static void Main(string[] args)
{
//build the datatable
MemberTable.Columns.Add("Id", typeof(int));
MemberTable.Columns.Add("EmailAddress", typeof(string));
MemberTable.Columns.Add("Body", typeof(string));
subject = args[0];
body = args[1];
smtp = args[2];
senderEmail = args[3];
sendViaSql = Convert.ToBoolean(args[4]);
//get members from database
DataTable members = Classes.EmailUtility.GetEmails();
foreach (DataRow row in members.Rows)
{
DataRow memberRow = MemberTable.NewRow();
memberRow["Id"] = row["Id"];
memberRow["EmailAddress"] = row["Email"];
memberRow["Body"] = body;
MemberTable.Rows.Add(memberRow);
}
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.Subject = subject;
msg.Body = body;
msg.From = senderEmail;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
foreach (DataRow row in MemberTable.Rows)
{
try
{
msg.To = row["EmailAddress"].ToString();
if (sendViaSql) //send through SQL Server
{
EmailUtility.SendEmail(msg.To, msg.Body, msg.Subject);
}
else
{
//send through via SMTP Server
System.Web.Mail.SmtpMail.SmtpServer = smtp;
System.Web.Mail.SmtpMail.Send(msg);
}
}
catch { }
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.