简体   繁体   中英

SMTP works in Visual Studio but not when uploading to production IIS Server

I have narrowed this down to an issue with IIS. I am using system.net.mail to send emails. They work on my local box, but when I publish them to my IIS8 Server 2012 Server, the emails fail to send.

Try
        Dim mailMessage As New MailMessage("test@test.com", Me.ddlApprovers.SelectedValue)
        mailMessage.Subject = "TEST"

        mailMessage.Body = "TEST"

        Dim smtpClient As New SmtpClient(My.Settings.SMTP, 25)

        smtpClient.Send(mailMessage)
    Catch ex As Exception
        Me.lblAlertText.Text = "An error send email has occured. Contact your system administrator."
        ScriptManager.RegisterStartupScript(Me, Me.GetType(), "LaunchAlertPopup", "$(function() { AlertMessage(); });", True)
    End Try

I have downloaded an SMTP test tool and send emails just fine through it, so it has to be an issue with this website in IIS.

Many ISPs block port 25. Try sending through 465 or 587. It would also be worth checking for any firewall rules that could be blocking any of these ports.

We can only assume that you're using a valid host name for your SMTP client. This needs to exist or your messages will never send.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM