Great Minds must think alike. I just finished this not more than 15
minutes ago. There may be a better way to do it, but I know that this
works.
protected void btnSendUpload_C lick(object sender, EventArgs e)
{
string queryString = "Select Email From tblMailer";
string constring = "Data Source=GLSDBS03 ;Initial
Catalog=CCTS;Pe rsist Security Info=True;User
ID=UserID;Passw ord=Password";
using (SqlConnection connection = new
SqlConnection(c onstring))
{
connection.Open ();
SqlCommand command = new SqlCommand(quer yString,
connection);
SqlDataReader reader = command.Execute Reader();
while (reader.Read())
{
string captured = Convert.ToStrin g(reader["EMail"]);
try
{
SmtpClient mailSvr = new SmtpClientYour SMTP
CLient);
MailAddress from = new MailAddress(You r From
Address);
MailAddress to = new MailAddress(cap tured);
MailMessage msg = new MailMessage(fro m, to);
msg.Subject = "JACOBS CCTS Labor Upload";
msg.Body = "The attached text file contains Labor
Hours. " + Environment.New Line + Environment.New Line;
Attachment attach = new Attachment("\\\ \glsdbs03\\d
$\\File\\LaborF ile.txt");
msg.Attachments .Add(attach);
mailSvr.Send(ms g);
lbStatus.Text = "Labor has been Sent.";
}
catch (Exception ex)
{
lbStatus.Text = ex.Message;
}
}
}
}
I hope this helps
On Nov 21, 4:00 pm, "David C" <dlch...@lifeti meinc.comwrote:
I would like to have an email go to 2 email addresses but when I try it by
separating with semicolon or comma it fails. Can anyone help? below is my
code (see ToAddress string). Thanks.
David
strUser = UtilClass.GetUs erName(strUser)
'!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
Const ToAddress As String = "m...@myemail.c om"
Const FromAddress As String = "m...@myemail.c om"
'(1) Create the MailMessage instance
Dim mm As New System.Net.Mail .MailMessage(To Address,
FromAddress)
'(2) Assign the MailMessage's properties
mm.Subject = "Fileroom unhandled exception occurred!"
mm.Body = "User getting error is " & strUser & vbCrLf & _
String.Format(" An unhandled exception
occurred:{0}Mes sage: {1}{0}{0} Stack Trace:{0}{2}",
System.Environm ent.NewLine, ex.Message, ex.StackTrace)
mm.IsBodyHtml = False
'(3) Create the SmtpClient object
Dim smtp As New System.Net.Mail .SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.Send(mm)