Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET mailing
In my application I would like to send a mail and I am using the below code,
protected void SendMail()
   {
       // Gmail Address from where you send the mail
       var fromAddress = "xxxxx@gmail.com";
       // any address where the email will be sending
       var toAddress = txtto.Text.ToString();
       //Password of your gmail address
       const string fromPassword = "*****";
       // Passing the values and make a email formate to display
       string subject = "Testing";
       string body = "xxx";
 
       // smtp settings
       var smtp = new System.Net.Mail.SmtpClient();
       {
           smtp.Host = "smtp.gmail.com"
           smtp.Port = 587;
           smtp.EnableSsl = true;
           smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
           smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
           smtp.Timeout = 2000000;
       }
       // Passing values to smtp object
       smtp.Send(fromAddress, toAddress, subject, body);
   }
   protected void btnsend_Click(object sender, EventArgs e)
   {
       try
       {
         
           {
               SendMail();
              
           }
       }
       catch (Exception ex)
       {
           Response.Write("Could not send the e-mail - error" +ex.Message);
       }
 
   }
but I getting an error:
Could not send the e-mail - error: Failure sending mail.
 
[Edit]Code block added[/Edit]
Posted 18-Dec-12 0:59am
Edited 18-Dec-12 1:02am
ProgramFOX122.8K
v2
Comments
Kavitha le at 18-Dec-12 7:21am
   
Its strange nobody knows the answer??
Kavitha le at 18-Dec-12 9:38am
   
Error: Unable to connect to the remote server
Surendra0x2 at 18-Dec-12 12:20pm
   
try to deactivate your Antivirus then send mail.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you tried this way refer link below
 
http://asp.net-tutorials.com/misc/sending-mails/[^]
 
you also need to have setting in web.config
 
refer
 
http://community.discountasp.net/showthread.php?t=9157[^]
  Permalink  
v2
Comments
Kavitha le at 18-Dec-12 9:37am
   
Getting error:
Unable to connect to the remote server
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try out this code :
 
var smtp = new System.Net.Mail.SmtpClient();
   {
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.EnableSsl = true;
       smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
       smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
       smtp.Timeout = 20000;
   }
   // Passing values to smtp object
   smtp.Send(fromAddress, toAddress, subject, body);
  Permalink  
Comments
Kavitha le at 18-Dec-12 9:05am
   
The same code am using...still getting error
Kavitha le at 18-Dec-12 9:37am
   
Error is:
Unable to connect to the remote server
Krunal Rohit at 18-Dec-12 11:40am
   
How it could be possible.. I've tried it out by myself..
Kavitha le at 19-Dec-12 4:34am
   
Its strange, might be problem with my proxy.
Am trying to send mail from my gmail account so anything need to change in gmail account settings?
Krunal Rohit at 19-Dec-12 8:18am
   
No..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Please refer following link:
http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail[^]
 
also check with debugger that smtp.send function has all proper values.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
 
Have a look at this tip:
Sending an Email in C# with or without attachments: generic routine.[^]
Check also your firewall settings.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 841
1 OriginalGriff 245
2 Volynsky Alex 205
3 Kishore Pogaru 140
4 Magic Wonder 129
0 OriginalGriff 5,640
1 Sergey Alexandrovich Kryukov 4,693
2 CPallini 4,540
3 George Jonsson 3,132
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100