Hi All,
I am having difficulties sending an email from a web page that I created to my own email. This particular web pages is suppose to be a feedback form where people can leave feedback about the site and it should send the message to my email. The Exception message I get is: "Failure sending mail." Here is the piece of code I use to handle the email sending. If anyone can shed some light on this issue, it would be greatly appreciated :)
protectedvoid btnSubmit_Click(object sender,EventArgs e){
try
{
SmtpClient emailClient =newSmtpClient();MailMessage email =newMailMessage();
emailClient.Host ="localhost";emailClient.Port = 25;
email.To.Add(newMailAddress("kevintrinh.n@dotnet.itags.org.gmail.com"));email.From =newMailAddress(txtEmail.Text);
email.Subject ="Enquiry";email.Body ="Testing";
email.IsBodyHtml =false;emailClient.Send(email);
}
catch(Exception ex){
Response.Write(ex.Message);
}
}
Cheers guys
Check the SMTP logs to start troubleshooting this.
Jeff
You'll need more detailed error info to get help.
One quick thing to check, is antivirus software on your computer blocking your code from sending email?
I have a feedback page, too, and it works great. Here's my code:
The Click Event:
public void SendMail_Click(object sender, EventArgs e)
{
SendMail();
}
public void SendMail()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress(WebConfigurationManager.AppSettings["DefaultMailFrom"], "Internet User: " + txtName.Text);
mail.To.Add(WebConfigurationManager.AppSettings["DefaultMailTo"]);
if (txtEmail.Text.Trim() != "")
mail.ReplyTo = new MailAddress(txtEmail.Text.Trim());
//set the content
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
mail.Body += "\n\nReferring page: " + lnkReferrerF.NavigateUrl;
//send the message
SmtpClient smtp = new SmtpClient(WebConfigurationManager.AppSettings["DefaultMailServer"]);
smtp.Send(mail);
}
And then under <AppSettings> in the web.config file I have:
<add key="DefaultMailFrom" value="mailer@.site.com" />
<add key="DefaultMailReplyTo" value="david@.site.com" />
<add key="DefaultMailTo" value="david@.site.com" />
<add key="DefaultMailServer" value="mailserver name" />
Hope this helps.
Kevin-
If you're currently trying to run this on your local PC, make sure you have an SMTP server running on your box. Open up the IIS Configuration in your Control Panel > Administrative Tools and make sure the Default SMTP Virtual Server is started.
Thanks~
Hi everyone,
Thanks for all the insight...I really appreciate it. I will take a look at all your suggestions and follow up. Thanks again guys :)
Cheers
Dear Friend,
Also check out if you are running any anti virus scanners. Sometimes those applications blocks the port for sending out the emails. You may need to configure them to send out the emails.
tanglin05:
Kevin-
If you're currently trying to run this on your local PC, make sure you have an SMTP server running on your box. Open up the IIS Configuration in your Control Panel > Administrative Tools and make sure the Default SMTP Virtual Server is started.
Thanks~
Hi Todd,
I think this is my problem. I've taken a look on the net and all the tutorials explain the procedure to configure the virtual smtp server for all windows other than VISTA. Just wondering if you know how to configure the settings on vista or if you/anyone know of any links that may point me in the right direction?
In the mean time I will continue looking for explanations online :)
Thanks mate.
Kevin-
I'm away from my desktop right now, so I don't have Vista handy. Based on these posts I found on the Net, it appears SMTP may not be in Vista (?!):
http://tfl09.blogspot.com/2007/03/smtp-in-vista-or-not.html
http://weblogs.asp.net/steveschofield/archive/2006/12/19/iis7-post-23-vista-and-smtp-server-where-is-it.aspx
I can't verify this right now, so if anyone knows otherwise please correct me. The links I provided have references to shareware SMTP servers that you can install to solve your problem, so this may help you get on your way.
Thanks~
Todd you're a champ mate...I downloaded a free smtp server and it sends now



Just some tips for anyone else with a similar problem. If you are trying to send emails from you local machine, make sure the ISP you are going through does not block port 25 (else your emails cannot be sent). I found that I could send from uni but I couldn't send from home (for the above reason)
If everything seems ok with your code and server setup however you do not receive any emails.....check your SPAM folder!! (This is also what happened to me; spent 2 long hours trying to work out why I wasn't receiving any emails!)
I found the following SMTP server application to be the most useful one out there as it allows you to test whether port 25 is open. You can download the free 30day trial here1st SMTP Server
Hope this helps anyone facing the same email problems as I did');" title="Smile -
">
Thanks again everyone for your help');" title="Yes -
">
0 comments:
Post a Comment