Click here to Skip to main content
Rate this: bad
good
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
Edited 31-Aug-10 8:45am
v3
Comments
senguptaamlan at 31-Aug-10 1:56am
   
go through the stack trace of the error and if possible post the same here
S M P at 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 at 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 at 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 at 2-Sep-10 3:56am
   
Ok brother i m much confused now i have put the code in config:







 
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 at 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 2

Your Network credentials are wrong
  Permalink  
Comments
Sandeep Mewara at 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 at 1-Sep-10 4:53am
   
Ok my mistake then, i didn't see such network crendentials till today

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 382
1 DamithSL 275
2 OriginalGriff 245
3 Zoltán Zörgő 149
4 Dave Kreskowiak 110
0 OriginalGriff 7,575
1 DamithSL 5,529
2 Sergey Alexandrovich Kryukov 5,279
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 21 Jan 2013
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