Results 1 to 23 of 23

Thread: [2005] Sending an email using Gmail?

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved [2005] Sending an email using Gmail?

    Hello everyone,

    It has been a while since i posted. Am now starting my VS2005 shoes

    I would like to send an email using VS2005 via Gmail.

    I know that it is possible, but am puzzled on how to establish a secure SSL connection.

    Below is extracted from the Gmail help site

    To configure your client manually:

    Open Outlook or Outlook Express.
    Click the 'Tools' menu, and select 'Accounts...'
    Click 'Add,' and then click 'Mail...'
    Enter your name in the 'Display name:' field, and click 'Next.'
    Enter your full Google Mail email address ([email protected]) in the 'Email address:' field, and click 'Next.'
    Enter 'pop.googlemail.com' in the 'Incoming mail (POP3, IMAP or HTTP) server:' field. Enter 'smtp.googlemail.com' in the 'Outgoing mail (SMTP) server:' field.
    Click 'Next.'
    Enter your Google Mail username (including '@googlemail.com') in the 'Account name:' field. Enter your Google Mail password in the 'Password:' field, and click 'Next.'
    Click 'Finish.'
    Highlight 'pop.googlemail.com' under 'Account,' and click 'Properties.'
    Click the 'Advanced' tab.
    Tick the box next to 'This server requires a secure connection (SSL)' under 'Outgoing Mail (SMTP).'
    Enter '465' in the 'Outgoing mail (SMTP):' field.
    Tick the box next to 'This server requires a secure connection (SSL)' under 'Incoming mail (POP3).' The port will change to 995.
    *The order of 'Outgoing' and 'Incoming' mail server fields varies by version. Make sure you enter the correct information in each field.
    Click the 'Servers' tab, and tick the box next to 'My server requires authentication.'
    Click 'OK.'
    Congratulations!
    Last edited by dinosaur_uk; Aug 24th, 2006 at 08:39 PM.
    If you find my thread helpful, please remember to rate me

  2. #2
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Re: [2005] Sending an email using Gmail?

    I don't have 2005, but I'm sure if you look into some of the properties of the MailMessage object and SmtpClient object you will find your answers. He is some basic code I found in anohter thread.

    VB Code:
    1. Dim Mail As New MailMessage
    2.  
    3.         With Mail
    4.             .To.Add("[email protected]")
    5.             .From = New MailAddress("[email protected]")
    6.             .Subject = "Some Subject"
    7.             .Body = "Some Body"
    8.         End With
    9.  
    10.         Dim SMTP As New SmtpClient("SMTP.SOMESERVER.NET")
    11.  
    12.         SMTP.Send(Mail)
    13.  
    14.         ' Cleanup
    15.         SMTP = Nothing
    16.         Mail.Dispose()
    Visual Studio .NET 2005/.NET Framework 2.0

  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    Ya...i know how to do that....just need to have a secure ssl connection
    If you find my thread helpful, please remember to rate me

  4. #4
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Re: [2005] Sending an email using Gmail?

    Here is a link to some CDO configurations that worked for me in .net 1.1 I'm not sure if it has changed in 2.0. I did not use SSL, but see that it has item property. See this link http://msdn.microsoft.com/library/de...22bb7ce17c.asp. Just look on the left for a smtpusessl field and add it. I think you need to change the port too.

    VB Code:
    1. Dim CurrentMessage As New System.Web.Mail.MailMessage
    2.             Dim sSmtpMail As System.Web.Mail.SmtpMail
    3.             CurrentMessage.To = "[email protected]"
    4.             CurrentMessage.Cc = "[email protected]"
    5.             CurrentMessage.From = "[email protected]"
    6.             CurrentMessage.Subject = "Hello World"
    7.             CurrentMessage.Body = "Go to he doulbe L."
    8.             If File.Exists("F:\RepReports\S" & sPR.Trim & ".pdf") Then
    9.                 Dim aAttachment As New System.Web.Mail.MailAttachment("F:\RepReports\S" & sPR.Trim & ".pdf", Mail.MailEncoding.Base64)
    10.                 CurrentMessage.Attachments.Add(aAttachment)
    11.                 attached = attached + " Shop Orders  "
    12.             End If
    13.            
    14.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ameritech.yahoo.com"
    15.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    16.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    17.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    18.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
    19.             CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
    20.             sSmtpMail.SmtpServer = "smtp.ameritech.yahoo.com"
    21.             sSmtpMail.Send(CurrentMessage)
    22.             AddToList(sPR.Trim, "E-Mail Sent")
    Visual Studio .NET 2005/.NET Framework 2.0

  5. #5

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    OK....

    i have managed to get this code from www.systemwebmail.net.

    VB Code:
    1. 'create the mail message
    2.         Dim mail As New MailMessage()
    3.  
    4.         'set the addresses
    5.         mail.From = New MailAddress("[email protected]")
    6.         mail.To.Add("[email protected]")
    7.  
    8.         'set the content
    9.         mail.Subject = "This is an email"
    10.         mail.Body = "this is the body content of the email."
    11.  
    12.         'send the message
    13.         Dim smtp As New SmtpClient("smtp.mail.yahoo.com", 587)
    14.  
    15.  
    16.         'to authenticate we set the username and password properites on the SmtpClient
    17.         smtp.Credentials = New Net.NetworkCredential("username", "Password")
    18.         smtp.Send(mail)

    But it still does not work. How can i tell if my ISP is blocking the emails?

    I am currently in china and it could be because of the restrictive ISP's that is why i cant connect to either yahoo or gmail smtp servers.

    The yahoo servers require me to have a secure authentication apparently. Here is the error:

    The SMTP server requires a secure connection or the client was not authenticated. The server response was: authentication required - for help go to http://help.yahoo.com/help/us/mail/pop/pop-11.html
    Anyone have any ideas?

    If i put
    VB Code:
    1. smtp.EnableSsl = True

    I get this error

    Server does not support secure connections.
    What the heck is going on?

    Cheers in advance!
    If you find my thread helpful, please remember to rate me

  6. #6

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    Apparently, yahoo wants money if you want to use their smtp servers...

    So i tried with Gmail, but no luck there either
    If you find my thread helpful, please remember to rate me

  7. #7
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    Re: [2005] Sending an email using Gmail?

    take a look at this for reference. That way you dont need an outside smtp server to send mail:

    http://www.vbdotnetheaven.com/Code/M...testserver.asp

  8. #8

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    Nah, it doesn't work...

    It still requires an external SMTP server to relay email messages to the outside work
    If you find my thread helpful, please remember to rate me

  9. #9
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    413

    Re: [2005] Sending an email using Gmail?

    Have you tried Free SMTP server?

    http://www.softstack.com/freesmtp.html
    Visual Studio .NET 2005/.NET Framework 2.0

  10. #10

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    yup.....it has sorted my problem..

    how can i get my program to run it? (and then minimise it...)
    If you find my thread helpful, please remember to rate me

  11. #11

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    Ok....i found an article on the net on how to get GMail to work with .Net 2.0

    I will post my code shortly. It is excellent! No need for Freesmtp...
    If you find my thread helpful, please remember to rate me

  12. #12
    Hyperactive Member demon.KILER's Avatar
    Join Date
    Jul 2006
    Location
    I cannot remember !?
    Posts
    408

    Re: [2005] Sending an email using Gmail?

    hi every one I don't know why some one said

    Apparently, yahoo wants money if you want to use their smtp servers.
    but this code works perfectly
    VB Code:
    1. Dim username As String = us.Text
    2.         Dim domin As String
    3.         Dim body As String = bo.Text
    4.         Dim tooo As String = too.Text
    5.         Dim subject As String = subj.Text
    6.         Dim sender1 As String = se.Text
    7.  
    8.         Select Case ListBox1.SelectedIndex
    9.             Case 0
    10.                 domin = "gmail"
    11.             Case 1
    12.                 domin = "hotmail"
    13.             Case 2
    14.                 domin = "msn"
    15.             Case 3
    16.                 domin = "yahoo"
    17.         End Select
    18.         If domin = "" Then
    19.             domin = dom.Text
    20.         End If
    21.         If domin = "" Then
    22.             MsgBox("You must select the website that you have ur E-mail id ", MsgBoxStyle.Information)
    23.         End If
    24.  
    25.         Try
    26.             Dim message1, Conf, Fields, acsessing, sendemailgmail, dom
    27.             dom = "smtp." & domin & ".com"
    28.             message1 = CreateObject("CDO.Message")
    29.             Conf = CreateObject("CDO.Configuration")
    30.             Fields = Conf.Fields
    31.  
    32.             acsessing = "http://schemas.microsoft.com/cdo/configuration/"
    33.             Fields.Item(acsessing & "sendusing") = 2
    34.             Fields.Item(acsessing & "smtpserver") = dom
    35.             Fields.Item(acsessing & "smtpserverport") = 465
    36.             Fields.Item(acsessing & "smtpauthenticate") = 1
    37.             Fields.Item(acsessing & "sendusername") = username
    38.             Fields.Item(acsessing & "sendpassword") = ps.Text
    39.             Fields.Item(acsessing & "smtpusessl") = 1
    40.             Fields.Update()
    41.  
    42.             message1.To = tooo
    43.             message1.From = username
    44.             message1.Subject = subject
    45.             message1.HTMLBody = body
    46.             message1.Sender = sender1
    47.             message1.ReplyTo = username
    48.             message1.Configuration = Conf
    49.             ToolStripStatusLabel1.Text = "Message sending please wait"
    50.             sendemailgmail = message1.Send
    51.             MsgBox("  Your mail has been successfully sent", MsgBoxStyle.Information)
    52.  
    53.             us.Text = ""
    54.  
    55.             bo.Text = ""
    56.             too.Text = ""
    57.             subj.Text = ""
    58.             se.Text = ""
    59.         Catch ex As Exception
    60.  
    61.             MsgBox(ex.Message, MsgBoxStyle.Critical)
    62.         End Try
    VS 2005 .....Framework SDK 3.0

    "Its mostly the brave one who choose to not fight"

  13. #13

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    VB Code:
    1. Imports System.Net.Mail
    2. Imports System.Net.Security.AuthenticatedStream
    3. Imports System.Net.Mime
    4. Imports System.Threading
    5. Imports System.Text
    6.  
    7. Public Class class_EMAIL
    8.  
    9.  
    10.     Private Shared mailSent As Boolean = False
    11.  
    12.     Friend EmailSettings As SettingsStruct
    13.  
    14.  
    15.     Friend Structure SettingsStruct
    16.         Friend Recipent() As String
    17.         Friend From As String
    18.         Friend Subject As String
    19.         Friend Body As String
    20.         Friend Attachments() As String
    21.     End Structure
    22.  
    23.  
    24.     Friend formy As Helper.frmMain
    25.     Dim wait As New Helper.frmWait
    26.  
    27.     Sub Authenticate()
    28.         wait.Show(formy)
    29.         Dim msg As New System.Net.Mail.MailMessage()
    30.         msg.From = New MailAddress(EmailSettings.From)
    31.         'this is the recepients
    32.         Dim i As Integer
    33.         For i = 0 To EmailSettings.Recipent.Length - 1
    34.             msg.To.Add(EmailSettings.Recipent(i).ToString)
    35.         Next
    36.         'set the content
    37.         msg.Subject = EmailSettings.Subject & Date.Now.ToShortDateString & " " & Date.Now.ToShortTimeString
    38.         msg.SubjectEncoding = System.Text.Encoding.UTF8
    39.         msg.Body = EmailSettings.Body  'Me.txtEmailBody.Text
    40.         msg.BodyEncoding = System.Text.Encoding.UTF8
    41.         msg.IsBodyHtml = False
    42.         msg.Priority = MailPriority.High
    43.  
    44.  
    45.         'add the creddentials
    46.         Dim client As New SmtpClient()
    47.         client.Credentials = New System.Net.NetworkCredential("[email protected]", "PASSWORD")
    48.         client.Port = 587
    49.         client.Host = "smtp.gmail.com"
    50.         client.EnableSsl = True
    51.         AddHandler client.SendCompleted, AddressOf client_SendCompleted
    52.         Dim userState As Object = msg
    53.         Try
    54.             'you can also call client.Send(msg)
    55.             client.SendAsync(msg, userState)
    56.         Catch ex As System.Net.Mail.SmtpException
    57.             MessageBox.Show(ex.Message, "Send Mail Error")
    58.         End Try
    59.  
    60.     End Sub 'SendMail
    61.     Sub client_SendCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
    62.         Dim mail As MailMessage = CType(e.UserState, MailMessage)
    63.         Dim subject As String = mail.Subject
    64.  
    65.         If e.Cancelled Then
    66.             Dim cancelled As String = String.Format("[{0}] Send canceled.", subject)
    67.             MessageBox.Show(cancelled)
    68.             wait.Close()
    69.         End If
    70.         If Not (e.Error Is Nothing) Then
    71.             Dim [error] As String = [String].Format("[{0}] {1}", subject, e.Error.ToString())
    72.             MessageBox.Show([error])
    73.             wait.Close()
    74.         Else
    75.             MessageBox.Show("Message sent.")
    76.             wait.Close()
    77.         End If
    78.         mailSent = True
    79.     End Sub 'client_SendCompleted
    80. End Class

    Then to call onto this class,

    VB Code:
    1. Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
    2.         Dim cls As New class_EMAIL
    3.         'We need to find out who r we sending to.
    4. cls.EmailSettings.Recipent= "[email protected]"
    5. 'and so on.....
    6.  
    7.         cls.Authenticate()
    8.     End Sub
    If you find my thread helpful, please remember to rate me

  14. #14
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2005] Sending an email using Gmail?

    been looking for this code for a long time

    but when i copy/pasty this code i get an error that:
    Type 'Helper.frmMain' is not defined.
    Type 'Helper.frmwait' is not defined.

    How do i define these

    hope someone can help, happy new year

  15. #15
    Hyperactive Member Grunt's Avatar
    Join Date
    Oct 2004
    Location
    Las Vegas
    Posts
    499

    Re: [2005] Sending an email using Gmail?

    well, that is because you do not have those forms in your project. Add a form to your project called frmMain, and one called frmWait and those reference errors will disappear.

  16. #16
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2005] Sending an email using Gmail?

    nope that doesnt work, any other suggestions???

    VB Code:
    1. Friend formy As Helper.frmMain
    2.     Dim wait As New Helper.frmWait

    it is these two lines of code that fails

  17. #17
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2005] Sending an email using Gmail?

    no one

    i really need your help here

  18. #18
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] Sending an email using Gmail?

    Code:
       1.
          Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
       2.
                  Dim cls As New class_EMAIL
       3.
                  'We need to find out who r we sending to.
       4.
          cls.EmailSettings.Recipent= "[email protected]"
       5.
          'and so on.....
       6.
           
       7.
                  cls.Authenticate()
       8.
              End Sub
    I'm getting this error for my e-mail recipient.

    Error 1 Value of type 'String' cannot be converted to '1-dimensional array of String'.

    I'm not sure what this means other than this is an array and it doesn't like the string that i have.
    When I do it this way which i don't know why i would:

    cls.EmailSettings.Recipent(1)= "[email protected]"

    The error goes away but i get a null reference exception or something.

    Object reference not set to an instance of an object.

    Anyone help me out.?
    Tuber

    "I don't know the rules"

  19. #19
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    Re: [2005] Sending an email using Gmail?

    Sorry I found it. I know what it was but i couldn't find it in the code.

    The variable had () at the end. Probably from cutting and pasting.

    Sorry.
    Tuber

    "I don't know the rules"

  20. #20

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: [2005] Sending an email using Gmail?

    some info i copied from another site

    1. Check these important settings:
    a. My outgoing server requires authentication (or Password or
    Challenge/Response for iMac)
    b. Change the server timeout time from 1 min to 5 min
    c. Uncheck leave a copy of email on server.
    d. Try alternate SMTP port number: 25, 465, or 587.
    e. Change the outgoing server to smtp.googlemail.com

    2. Do you have a firewall blocking the connection? Email virus
    checking? Popup Blocker? Temporarily disable them.


    3. Update Outlook to latest configuration. Outlook 2000 should have
    SP3. Outlook 2002 should have SP3. Outlook 2003 should have SP2.


    4. Use the Captcha verification to unlock your account
    https://www.google.com/accounts/DisplayUnlockCaptcha


    5. See if the solutions here will help
    http://www.slipstick.com/problems/nosend.htm


    6. You ISP may be blocking Gmail server. Use your ISP SMTP server.
    If you find my thread helpful, please remember to rate me

  21. #21
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [2005] Sending an email using Gmail?

    I got it to work with gmail but I had to run the unlock programme first. What does that actually do?

    I used the settings from this link:

    http://www.emailaddressmanager.com/t...-settings.html

  22. #22
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [2005] Sending an email using Gmail?

    It appears that gmail ignores the specified "From Address" and replaces it with my gmail address.

    If a user sends an email, I don't want replies to come to me - I want them to go back to the user.

    Is there any way of changing this behaviour?

  23. #23
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: [2005] Sending an email using Gmail?

    It works perfectly using Yahoo and the following settings:

    smtp.mail.yahoo.com
    port 25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width