smtp从ASP.NET发送邮件消息

时间:2016-12-26 20:23:23

标签: asp.net vb.net

我在asp.net网站上有一个表格,托管在tedata(托管公司),用户可以填写并发送给我们公司。我目前正在使用Gmail帐户对其进行测试。电子邮件从我的localhost发送正常,但当我将它发布到Web服务器时,邮件不会发送,并且没有错误消息,任何人都可以帮助我, 这是我的代码:

Public Sub SendMail()
        Dim fromAddress = "eisegypt2017@gmail.com"
        Dim toAddress = "toAddress"
        Dim fromPassword As String = "fromPassword"

        Dim subject As String = "Mail"
        Dim body As String = "From: " + yourname.Value + vbCrLf + vbCrLf
        body = body + "Company: " + yourcompany.Value + vbCrLf + vbCrLf
        body = body + "Email: " + youremail.Value + vbCrLf + vbCrLf
        body = body + "Phone: " + yourphone.Value + vbCrLf + vbCrLf
        body += "Subject: " + subject + vbCrLf + vbCrLf
        body += "Message: " + yourmessage.Value + vbCrLf

        ' smtp settings
        Dim smtp = New System.Net.Mail.SmtpClient()
        Dim omail As New System.Net.Mail.MailMessage
        smtp.Host = "smtp.gmail.com"
        smtp.Port = 587
        smtp.EnableSsl = True
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
        smtp.Credentials = New System.Net.NetworkCredential(fromAddress, fromPassword)
        smtp.Timeout = 20000

        ' Passing values to smtp object
         smtp.Send(fromAddress, toAddress, subject, body)

    End Sub

0 个答案:

没有答案