0

我一直在阅读 Stack Overflow 上的一些帖子,这些帖子看起来与我的相似,并且我已经调整了我的代码,但它仍然无法正常工作。我的代码在下面供您阅读:

Dim ss As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
    'Dim ss As SmtpClient = New SmtpClient("smtp.gmail.com",465 )
    'Dim ss As SmtpClient = New SmtpClient("smtp.gmail.com", 25)
    ss.Timeout = 10000
    ss.DeliveryMethod = SmtpDeliveryMethod.Network
    ss.UseDefaultCredentials = False
    ss.EnableSsl = True
    ss.UseDefaultCredentials = False
    ss.Credentials = New NetworkCredential("name@gmail.com", "name@123")


    Dim subject As String = "Approval request for Quotation with Order Number: " + Me.OrderNo

    Dim body As String = "Dear Sir/Madam," + vbCrLf + " This is to bring to your notice the quotation for the Client " + Me.cmbCustomer.SelectedItem.Text + " and Order Number " + Me.OrderNo & _
        " which is awaiting your approval." + vbCrLf + "Click here to view and approve the Quotation: http:192.168.20.7/appname/Sales/ManageInvoices.aspx" + vbCrLf & _
        " Kindly revert after approval. Thank you." + vbCrLf + "Regards."

    Dim To1, To2, To3 As String

    Dim mm As MailMessage = New MailMessage()
    mm.From = New MailAddress("name@gmail.com")

    To1 = "usernameTo1@domain.com"
    To2 = "usernameTo2@domain.com"
    To3 = "usernameTo3@gmail.com"
    'To is a collection of MailAddress types
    mm.To.Add(To1)
    mm.To.Add(To2)
    mm.To.Add(To3)

    mm.Subject = subject
    mm.Body = body

    mm.BodyEncoding = UTF8Encoding.UTF8
    'mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
    Try
        ss.Send(mm)
    Catch ex As SmtpException
        Me.lblerr.Text = "SMTP Err:" & ex.ToString
    End Try

那么是什么导致邮件无法到达目的地呢?我根本没有收到任何错误消息。请帮忙谢谢。

4

1 回答 1

0

对于 gmail,您需要将端口设置为 587。

<system.net>
    <mailSettings>
      <smtp from="myn@gmail.com ">
        <network host="smtp.gmail.com" defaultCredentials="false"
          port="587" userName ="me@gmail.com" password="pass@123" />
      </smtp>
    </mailSettings>
   </system.net>
于 2012-11-22T17:21:04.200 回答