problem using SmtpClient to send email from asp.net

G

Guest

The code below is a recommended way to send email with c# from my aspx page:


MailMessage mail = new MailMessage();
mail.From = new MailAddress("(e-mail address removed)");
mail.To.Add(new MailAddress(strTo));
mail.Subject = "ZipTax Survey Received";
mail.Body = body;
SmtpClient client = new
SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SmtpServer"]);
try
{
client.Send(mail);
}
catch (Exception ex)
{
Response.Write(ex);
}

My from, to, subject and body are all populated and not null. But I get the
error below when run from my asp.net host provider:

ERROR: System.ArgumentNullException: Value cannot be null. Parameter name:
value at System.Net.Mail.SmtpClient.set_Host(String value) at
ZipTaxSurvey.Button1_Click(Object sender, EventArgs e)



Can someone please advise?
Thanks,
jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top