Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am sending mail in asp.net, it shows nice message "Failure sending mail".

I used this code, please help me where it goes wrong.

C#:
 MailMessage mail = new MailMessage();
 mail.From = new MailAddress("Rupesh@RUPI-PC");
 mail.To.Add(new MailAddress("XXXXXX@gmail.com"));
 mail.Subject="Testing";
 mail.Body="testing the mail";
 SmtpClient client = new SmtpClient();
 client.host="localhost";
 client.port=25;

try
 {
     client.Send(mail);
     Response.Write("message sent successfully");
 }
 catch (Exception ex)
 {
     Response.Write(ex.Message);
 }


In IIS for SMTP E-mail the following details i provided
Email Address: Rupesh@RUPI-PC
Deliver e-mail to SMTP server: checked the Use localhost
Port=25
Authentication settings : selected Not Required

Please Suggest me whether i need to provide any further details in SMTP e-mail


Thank You
Rupesh
Posted
Updated 22-Feb-12 23:26pm
v2
Comments
Varun Sareen 23-Feb-12 5:26am    
edit for: added pre tag
Herman<T>.Instance 23-Feb-12 5:29am    
what you do is use catch (Exception ex)

If you want to see the underlaying SMTP-exception use:

catch (SmtpException exSmtp){Response.Write(exSmtp.Message); }

catch (Exception ex){Response.Write(ex.Message); }
To have better detail of the exception you can also use Response.Write(exSmtp.ToString());

 
Share this answer
 
v2
C#
SmtpClient client = new SmtpClient();
client.host="localhost";
client.port=25;

Do you have an SMTP server running on your local host? I thought not.
 
Share this answer
 
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
           MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
           MailMessage newmsg = new MailMessage ( mailfrom, mailto );

           newmsg.Subject = "Subject of Email";
           newmsg.Body = "Body(message) of email";

           ////For File Attachment, more file can also be attached

           Attachment att = new Attachment ( "G:\\code.txt" );
           newmsg.Attachments.Add ( att );

           SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
           smtps.UseDefaultCredentials = false;
           smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
           smtps.EnableSsl = true;
           smtps.Send ( newmsg );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900