Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
VB
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
Updated 16-Feb-17 22:01pm
v3
Comments
senguptaamlan 31-Aug-10 1:56am    
go through the stack trace of the error and if possible post the same here
Sandesh M Patil 31-Aug-10 10:03am    
Please write your code in code block

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.
 
Share this answer
 
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
 
Share this answer
 
Comments
[no name] 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.
[no name] 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?
[no name] 2-Sep-10 6:12am    
I got the sol just changed port number. Thank you all especially Sandeep bro
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);
 
Share this answer
 
Your Network credentials are wrong
 
Share this answer
 
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?
Sandesh M Patil 1-Sep-10 4:53am    
Ok my mistake then, i didn't see such network crendentials till today
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
 
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