使用启用了tls的服务器在VB.Net中发送电子邮件 [英] Send email in VB.Net with tls enabled server

查看:97
本文介绍了使用启用了tls的服务器在VB.Net中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于使用启用了TLS的SMTP服务器发送电子邮件的应用程序,并且此应用程序我想在Windows Server 2003上运行。当我在Windows Server 2012 R2上运行相同的应用程序时,它的运行正常,但在Windows Server 2003上无法运行

I am developing application for sending an email with TLS enabled SMTP server and this application I want to run on windows server 2003. When I run this same application on window server 2012 R2 its working perfect but it wont work on window server 2003. Is there any specific reason it wont work on window server 2003?


错误:SMTP服务器需要安全连接或客户端未通过身份验证吗? 。服务器响应为:5.7.1客户端未通过身份验证。

Error: SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.

我在应用程序中使用了以下代码:

I used below code in my application:

Public Sub sendemail()
    Dim SMTPMailServer As New System.Net.Mail.SmtpClient("xyz") 'tls enabled SMTP Server Name 
    Dim myMail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage("FromEmail", "ToEmail")
    With myMail
        .Subject = "Test Email with TLS enabled server"
        .Body = "Test Body"
        .Priority = Net.Mail.MailPriority.Normal
        .IsBodyHtml = True
    End With
    SMTPMailServer.Send(myMail)
    myMail = Nothing
End Sub


推荐答案

Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New _
        Net.NetworkCredential("username@gmail.com", "password")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress("YOURusername@gmail.com")
            mail.To.Add("TOADDRESS")
            mail.Subject = "Test Mail"
            mail.Body = "This is for testing SMTP mail from GMAIL"
            SmtpServer.Send(mail)
            MsgBox("mail send")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

这篇关于使用启用了tls的服务器在VB.Net中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆