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 am trying to sent email via my asp.net application
the code i use is as follows:
Dim msg As New MailMessage()
msg.From = fromaddr ' is a gmail address
msg.To.Add(toaddr) 
msg.Subject = subject
msg.Body = msgbody
Dim cred As New System.Net.NetworkCredential("myusername@gmail.com","mypassword")
Dim client As New SmtpClient()
client.Host ="smtp.gmail.com"
client.Port = 465
client.EnableSsl = True
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.UseDefaultCredentials = False
client.Credentials = cred
 
client.Send(msg)
when i run it the application goes into an indefinite loop.
if i set the port no as 587 i get an operation timeout error.
also if change the code into the following one:
Dim msg As New MailMessage()
        msg.From = fromaddr
        msg.To.Add(toaddr)
        msg.Subject = subject
        msg.IsBodyHtml = True
        msg.Body = msgbody
 
        Dim client As New SmtpClient("localhost")
 
        client.Send(msg)
 

the mail is present in the C:\Inetpub\mailroot\Queue folder but does not reach the destination.
 
Note: my outlook is also configured for the gmail sever and works fine.
 
please help me detect the problem.
 
thanks in advance.
Posted 26-Apr-11 9:24am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I reckon you need to use port 587. And if it times out, then there's a network issue there - possibly a firewall.
  Permalink  
Comments
aruna_0990 at 27-Apr-11 1:24am
   
so do i need to do some changes in the firewall or in the code???
can u suggest something...
thanx...
Albin Abel at 27-Apr-11 12:36pm
   
Sharp answer. 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

As rightly pointed by Nish, AFAIR, GMail uses 587 as the port.
 
If that does not work, then 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 (It's simpler and helps):
 <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[^]
Tutorials on sending Email in ASP.NET[^]
  Permalink  
Comments
aruna_0990 at 27-Apr-11 10:02am
   
thanx it worked when i used 587..i increased the timeout seconds
Sandeep Mewara at 27-Apr-11 10:05am
   
Good to know! :)
 
Albin Abel at 27-Apr-11 12:36pm
   
Looks like Op forgot to vote. My 5 and 5 on behalf of OP
Sandeep Mewara at 27-Apr-11 12:48pm
   
:)
 
Well, forgot? I guess we both know by now that most of them move on once they get an answer that works.
 
Thanks for the 5.
Albin Abel at 27-Apr-11 14:22pm
   
Looks like there is a good response. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Take a look at this article[^], could give you and idea on what you might be doing wrong. At a glance, I am not able to find any issue with your code.
  Permalink  
Comments
aruna_0990 at 27-Apr-11 1:22am
   
hey i read the article but it doesn't solve my problem... thanx anyways

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 BillWoodruff 85
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 27 Apr 2011
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