views:

80

answers:

2
+1  Q: 

asp.net send mail

i am writing a program to send mail using asp.net, it gives me an error as the "SendUsing" configuration value is invalid. Here is my code

protected void Button2_Click(object sender, EventArgs e)
{
    MailMessage msg = new MailMessage();
    msg.To = "[email protected]";
    msg.From = "[email protected]";
    msg.Subject = "hello";
    SmtpMail.Send(msg);
}
+2  A: 

You need to add the SMTP server you want to use, something like

System.Web.Mail.SmtpMail.SmtpServer = "mail.provider.com";

Perhaps you might want to take a look at the System.Net.Mail, which is the new mail class in .Net 2, System.Web.Mail is obsolete.

Jan Jongboom
Not if the SMTP server is local, anyway +1, because that's the common reason.
Moayad Mardini
A: 

Typically this exception has to deal with the following line of code (or I should say ABSENCE of the following line of code):

SmtpMail.SmtpServer = "mail.your-domain.com"

By default, if SmtpMail.SmtpServer is not set, System.Web.Mail is supposed to use localhost as the default property. However, for some reason this doesn't appear work.

You could have done a simple google search for this ;-)

Source

Shoban