0

I need to send an email using tls how do i send it in vb.net? Heres my server information which i confirmed in thunderbird since it requires manual entry for my server: 1. smtp server: pod51004.outlook.com 2. port: 587 3. TLSSTART is connection security from what i remember

Im using live@edu email services for this scenario. Heres my attempted code:

Class Mailer
        ''one static method for sending e-mails
        Shared Sub SendMail(ByVal [From] As String, ByVal [To] As String, _
                            ByVal Subject As String, ByVal Body As String, ByVal MailServer _
                            As String, Optional ByVal IsBodyHtml As Boolean = True, _
                            Optional ByVal MailPort As Integer = 25, _
                            Optional ByVal Attachments() As String = Nothing, Optional _
                            ByVal AuthUsername As String = Nothing, Optional ByVal _
                            AuthPassword As String = Nothing)

            'On Error GoTo ErrorHandler
            'create a SmtpClient object to allow applications to send 
            'e-mail by using the Simple Mail Transfer Protocol (SMTP).
            Dim MailClient As SmtpClient = New SmtpClient(MailServer, MailPort)
            MailClient.EnableSsl = True
            MailClient.DeliveryMethod = SmtpDeliveryMethod.Network
            'MailClient.UseDefaultCredentials = False
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
            Dim nc As NetworkCredential = New NetworkCredential(AuthUsername, AuthPassword)
            ''create a MailMessage object to represent an e-mail message
            ''that can be sent using the SmtpClient class
            Dim MailMessage = New MailMessage( _
            [From], [To], Subject, Body)
            ''sets a value indicating whether the mail message body is in Html.
            MailMessage.IsBodyHtml = IsBodyHtml
            ''sets the credentials used to authenticate the sender
            If (AuthUsername IsNot Nothing) AndAlso (AuthPassword _
                                                     IsNot Nothing) Then
                MailClient.Credentials = nc


            End If
            Dim 
            ''add the files as the attachments for the mailmessage object
            If (Attachments IsNot Nothing) Then
                For Each FileName In Attachments
                    MailMessage.Attachments.Add( _
                    New Attachment(FileName))
                Next
            End If
            MailClient.Send(MailMessage)
            ''ErrorHandler:
            '' MsgBox("My error")
        End Sub
    End Class

Anyone im up for ideas?

StingyJack
  • 19,041
  • 10
  • 63
  • 122
jeffery
  • 322
  • 4
  • 19
  • possible duplicate of [C# ASP.NET Send Email via TLS](http://stackoverflow.com/questions/2057227/c-sharp-asp-net-send-email-via-tls) – StingyJack Sep 05 '12 at 19:46
  • How do you know you are NOT sending the mail over a secure connection? – StingyJack Sep 05 '12 at 19:48
  • No im creating an vb.net windows forms program not asp.net. Yes their is a difference. the error code it give me is the same as in this thread:http://stackoverflow.com/questions/10507166/listening-to-port-5060 – jeffery Sep 06 '12 at 13:46
  • please note for answers: i have tryed mailclient.enablessl = true and serivcepointmanager as you can see above (service point manage i might have not done correctly). – jeffery Sep 06 '12 at 13:55
  • There is no error code in your question. – StingyJack Sep 06 '12 at 21:56

1 Answers1

0

Sorry to confuse answerers, but getting down to the general error It was giving was access denied. It turns out this is due to mcafee blocking the connection, thinking it was a worm trying to mass send emails (lol). But thanks for the help. P.S. remember to check mcafee in future cases of similar problems. Its a pain to get automated emails to work with mcafee.

jeffery
  • 322
  • 4
  • 19