Click here to Skip to main content
12,631,123 members (31,483 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
I have used gmail for sending mail localy which worked fine but when i uploaded the same file on server the "Failure sending mail." error occured.
Here is the code that I have written:
Dim message As New MailMessage
message.From = New MailAddress("xxx@gmail.com")
message.To.Add(New MailAddress("xxx@yahoo.com"))
message.Subject = test mail""
message.Body = "Hi you have got a test mail from me!"
Dim client As New SmtpClient
client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxxxxxx")
client.Port = 587
client.Host = "smtp.gmail.com"
client.EnableSsl = True
client.Send(message)

Please help me!
Posted 30-Aug-10 20:47pm
Updated 31-Aug-10 8:45am
v3
Comments
senguptaamlan 31-Aug-10 1:56am
   
go through the stack trace of the error and if possible post the same here
S M P 31-Aug-10 10:03am
   
Please write your code in code block
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If it works on your local machine and not on the server, then the server cannot access the mail server you're using, for some reason.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

It can be because of various reasons. You need to look at them one by one.

Is the port open? Firewall permissions in place?
Further make sure you have configured SMTP configuration in Web.Config:
<system.net>
   <mailSettings>
     <smtp from="abc@somedomain.com">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
     </smtp>
   </mailSettings>
</system.net>
If needed, have a look at this Microsoft Video tutorial:
Use ASP.NET to send Email from Website[^]

If needed, there are lots of article on this very site on how to send emails
  Permalink  
Comments
Sunil Tarwara 1-Sep-10 3:59am
   
Cant i add SMTP configuration in coding page instead of Web.Configuration as i have done like from, host, port, user name, password?
Sandeep Mewara 1-Sep-10 15:22pm
   
No you cannot. It's a site based setting for sending emails. I don't see an issue why you don't want to do this in config. Infact that would be easy to maintain and lookup.
Sunil Tarwara 2-Sep-10 3:56am
   
Ok brother i m much confused now i have put the code in config:
<system.net>
<mailsettings>
<smtp from="xxx@gmail.com">
<network defaultcredentials="true" host="smtp.gmail.com" port="587" username="xxx@gmail.com" password="xxx">




and this is the code for button click on which mail will sent:
Dim message As New MailMessage
message.From = New MailAddress("xxx@gmail.com")
message.To.Add(New MailAddress("xxx@yahoo.com"))
message.Subject = "test mail"
message.Body = "Hi you have got a mail"
Dim client As New SmtpClient
client.Credentials = New System.Net.NetworkCredential("xxx@gmail.com", "xxx")
client.Port = 587
client.Host = "smtp.gmail.com"
client.EnableSsl = True
client.Send(message)
Its working on localhost but not on server! Now please do tell me what and where to edit?
Sunil Tarwara 2-Sep-10 6:12am
   
I got the sol just changed port number. Thank you all especially Sandeep bro
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

NetworkCredential ncrd = new NetworkCredential();
ncrd.UserName = fromemail;
ncrd.Password = frompwd;
SmtpClient MailClient = new SmtpClient();
MailClient.Host = "smtp.gmail.com";
MailClient.Port = 587;
MailClient.UseDefaultCredentials = true;
MailClient.Credentials = ncrd;
MailClient.EnableSsl = true;
MailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
MailClient.Send(msg);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Your Network credentials are wrong
  Permalink  
Comments
Sandeep Mewara 31-Aug-10 13:43pm
   
Don't tell me you really expected him to provide right credentials here. :)

Any specific reason why you pointed just the Network credentials?
S M P 1-Sep-10 4:53am
   
Ok my mistake then, i didn't see such network crendentials till today
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

if you are working locally it works fine

bt at time of on line

your server like. free hosting sites : somee.com

cant't give permission to acces gmail or smtp server it means it block server to gain access
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 17 Nov 2015
Copyright © CodeProject, 1999-2016
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