DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Problem, sending email via smtp.gmail.com

  1. #1
    Join Date
    Mar 2008
    Location
    Blaricum, The Netherlands
    Posts
    78

    Problem, sending email via smtp.gmail.com

    Hello,

    I have an application that should send an email when an error occurs.
    The code i use is:
    Code:
    Public Shared Sub Send( _
                ByVal Body As String, _
                ByVal Subject As String, _
                ByVal DeliveryOptions As DeliveryNotificationOptions, _
                ByVal Priority As MailPriority, _
                ByVal ToMail As MailAddress, _
                ByVal FromMail As MailAddress, _
                ByVal AttachFile As String, _
                ByVal bcc As MailAddress, _
                ByVal CC As MailAddress)
    
        Dim mail As New MailMessage
        ' Check that the connection is good
        If Not DoesPing("smtp.gmail.com") Then
            ' Only go on  if the server is reachable
            Return
        End If
    
        Using mail
            Try
                With mail
                    If Not AttachFile Is Nothing AndAlso System.IO.File.Exists(AttachFile) Then
                        'check that file exists Throw exception?
                        Dim item As New Attachment(AttachFile)
                        .Attachments.Add(item)
                    End If
                    If Not bcc Is Nothing Then .Bcc.Add(bcc)
                    If Not CC Is Nothing Then .CC.Add(CC)
                    .BodyEncoding = System.Text.Encoding.Unicode
                    .To.Add(ToMail)
                    .From = FromMail
                    .Priority = Priority
                    .DeliveryNotificationOptions = DeliveryOptions
                    If Not FromMail Is Nothing Then .ReplyTo = FromMail
                    .Sender = FromMail
                    .Subject = Subject
                    .Body = Body
                    Dim SmtpMail As New SmtpClient
                    With SmtpMail
                        .Host = "smtp.gmail.com"
                        .Port = 465
                        .EnableSsl = True
                        .DeliveryMethod = SmtpDeliveryMethod.Network
                        .Credentials = New NetworkCredential("MyUsername@gmail.com", "MyPassword")
                        .Send(mail)
                    End With 'smtpMail
    
                End With 'mail
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Using 'mail
    End Sub
    However... I get an error.
    The message is: The requested operation timed out

    What can be the reason for that please?
    Does anybody know?

    Friendly greetings
    Rens

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Does this happen all the time, or only with certain mail providers?

  3. #3
    Join Date
    Mar 2008
    Location
    Blaricum, The Netherlands
    Posts
    78
    Well.....

    I have tried 3 different smtp server I have access to, but I can't get it to work....

    gmail says: Timeout
    All others: Failure sending mail

  4. #4
    Join Date
    Mar 2008
    Location
    Blaricum, The Netherlands
    Posts
    78
    I have searched the internet (again) and found 5 examples in VB.NET, sending mail via google.
    None of them work for me.
    Every one gets timed out.

    I have tried to send mail using Outlook Express on XP and Live Mail on Vista.
    Both work fine.

    Help?!

  5. #5
    Join Date
    Mar 2008
    Location
    Blaricum, The Netherlands
    Posts
    78
    I'm searching the internet for days now, but can't find the answer anywhere.
    There are more people that have the same problem.
    But I can only find their questions, not the answers......

    Nobody can help?
    Is it really true?

  6. #6
    Join Date
    Apr 2009
    Posts
    1
    Change .Port = 465 to .Port = 587 or .Port = 25

    This worked in my case.

    587 is the Outgoing server (SMTP) port for IMAP. It uses a TLS
    encryption connection.

    465 is the Outgoing server (SMTP) port for pop. It uses an SSL
    encryption connection.

  7. #7
    Join Date
    Mar 2008
    Location
    Blaricum, The Netherlands
    Posts
    78
    If it would only be so simple.
    I'm afraid it is not.
    tried it.
    No go.

Similar Threads

  1. Replies: 0
    Last Post: 02-29-2008, 09:33 AM
  2. Sending email with VB program
    By yourwar in forum .NET
    Replies: 2
    Last Post: 05-31-2006, 03:04 PM
  3. Replies: 4
    Last Post: 08-18-2005, 10:33 AM
  4. Sending a HTML email using asp?
    By Stuart in forum ASP.NET
    Replies: 1
    Last Post: 01-10-2001, 02:26 PM
  5. Sending email when a record is added
    By MikeV in forum Database
    Replies: 1
    Last Post: 12-28-2000, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center