0

我几乎尝试了所有事情,但无法让它发挥作用。我将不胜感激。谢谢

   Imports Microsoft.VisualBasic, System.Net.Mail

   Shared Sub SendMailHTML(ByVal ToAdd, ByVal FromAdd, ByVal Message, ByVal Subject)

    Dim mail As New MailMessage()

    Dim SmtpServer As New SmtpClient()
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.Credentials = New Net.NetworkCredential("xxxx@gmail.com", "xxxxxx")
    SmtpServer.UseDefaultCredentials = False
    SmtpServer.Port = 465
    SmtpServer.EnableSsl = True
    SmtpServer.Timeout = 5000
    SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network

    Try
        mail.From = New MailAddress("xxxxx@gmail.com")
        mail.To.Add("xxxxxx@gmail.com")

        SmtpServer.Send(Mail)
    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try

End Sub
4

1 回答 1

0

您可以尝试将 gmail 的端口更改为 587。并且还添加了 try 块

    mail.Subject= ...
    mail.Body= ...

(在此处添加合适的字符串)

也尝试在没有的情况下运行它

    SmtpServer.UseDefaultCredentials = False
    SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network

如果您需要,我可以在 C# 中添加我的代码,因为我不知道 VB

于 2013-10-06T03:54:48.433 回答