Click here to Skip to main content
13,044,467 members (58,514 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i am trying to sent email via my application
the code i use is as follows:
Dim msg As New MailMessage()
msg.From = fromaddr ' is a gmail address
msg.Subject = subject
msg.Body = msgbody
Dim cred As New System.Net.NetworkCredential("","mypassword")
Dim client As New SmtpClient()
client.Host =""
client.Port = 465
client.EnableSsl = True
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.UseDefaultCredentials = False
client.Credentials = cred

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.Subject = subject
        msg.IsBodyHtml = True
        msg.Body = msgbody
        Dim client As New SmtpClient("localhost")

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 8:24am
Rate this: bad
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.
aruna_0990 27-Apr-11 1:24am
so do i need to do some changes in the firewall or in the code???
can u suggest something...
Albin Abel 27-Apr-11 12:36pm
Sharp answer. 5
Rate this: bad
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):
     <smtp from="">
       <network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />

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[^]
aruna_0990 27-Apr-11 10:02am
thanx it worked when i used 587..i increased the timeout seconds
Sandeep Mewara 27-Apr-11 10:05am
Good to know! :)

Albin Abel 27-Apr-11 12:36pm
Looks like Op forgot to vote. My 5 and 5 on behalf of OP
Sandeep Mewara 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 27-Apr-11 14:22pm
Looks like there is a good response. :)
Rate this: bad
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.
aruna_0990 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 27 Apr 2011
Copyright © CodeProject, 1999-2017
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