【问题标题】:how do i send email message using tls?如何使用 tls 发送电子邮件?
【发布时间】:2012-08-30 14:10:34
【问题描述】:

我需要使用 tls 发送电子邮件,如何在 vb.net 中发送? 这是我在 Thunderbird 中确认的服务器信息,因为它需要手动输入我的服务器: 1. smtp 服务器:pod51004.outlook.com 2.端口:587 3. TLSSTART 是我记忆中的连接安全

我在这种情况下使用 live@edu 电子邮件服务。 这是我尝试的代码:

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

有人想出主意吗?

【问题讨论】:

  • 你怎么知道你没有通过安全连接发送邮件?
  • 没有即时创建 vb.net windows 窗体程序而不是 asp.net。是的,他们是不同的。它给我的错误代码与此线程中的相同:stackoverflow.com/questions/10507166/listening-to-port-5060
  • 请注意答案:我已经尝试过 mailclient.enablessl = true 和 serivcepointmanager,如您所见(服务点管理我可能没有正确完成)。
  • 您的问题中没有错误代码。

标签: vb.net email


【解决方案1】:

很抱歉让回答者感到困惑,但要解决它给出的一般错误是访问被拒绝。事实证明,这是由于 mcafee 阻止了连接,认为这是一个试图大量发送电子邮件的蠕虫(哈哈)。但感谢您的帮助。附言记得在以后遇到类似问题时检查 mcafee。让自动电子邮件与 mcafee 一起工作很痛苦。

【讨论】:

    猜你喜欢
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    • 2011-11-29
    • 2010-11-06
    • 2018-02-20
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多