如何在 web.config 中配置 SMTP 设置 [英] How to configure SMTP settings in web.config

查看:75
本文介绍了如何在 web.config 中配置 SMTP 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修复继承网站的电子邮件问题,但无权访问代码(即只有编译后的文件).此站点需要托管在具有不同 SMTP 服务器的新 Web 服务器上.

在反编译部分代码后,我可以看到电子邮件是使用如下代码片段中的方法发送的,并且 SMTP 设置为 smtpMail.SmtpServer=localhost"但我的新网络服务器的 SMTP 服务器是relay.tagadab.com";我们怎么可能在 web.config 中配置它,以便 localhost 被视为relay.tagadab.com"

导入 Microsoft.VisualBasic、System.Web.MailShared Sub SendMail(ByVal ToAdd, ByVal FromAdd, ByVal Message, ByVal Subject)Dim msgMail As New MailMessage()msgMail.To = ToAddmsgMail.From = FromAddmsgMail.Subject = 主题msgMail.Headers.Add("X-Mailer", "ASP.NET")msgMail.BodyFormat = MailFormat.TextmsgMail.Body = 消息'SmtpMail.SmtpServer = "mail.the-radiator.com";SmtpMail.SmtpServer = 本地主机"SmtpMail.Send(msgMail)结束子

我在 web.config 中添加了此部分,但这并没有什么区别

<邮件设置><smtp><网络主机=relay.tagadab.com";端口=25"/></smtp></mailSettings></system.net>

解决方案

Web.Config 文件:

<预><代码><配置><system.net><邮件设置><smtp from="yourmail@gmail.com"><网络主机="smtp.gmail.com"端口=587"用户名="您的邮箱@gmail.com"密码=你的密码"enableSsl="true"/></smtp></mailSettings></system.net></配置>

I'm trying to fix an email issue with an inherited website and don't have access to the code (i.e. just the compiled files). This site needs to be hosted on a new web server having a different SMTP server.

Upon decompiling bits of the code I can see emails are sent using method like below in code snippet and SMTP is set as smtpMail.SmtpServer="localhost" but my new webserver's SMTP server is "relay.tagadab.com" how can we possibly configure this in web.config so that localhost is taken as "relay.tagadab.com"

Imports Microsoft.VisualBasic, System.Web.Mail

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

    Dim msgMail As New MailMessage()

    msgMail.To = ToAdd
    msgMail.From = FromAdd
    msgMail.Subject = Subject
    msgMail.Headers.Add("X-Mailer", "ASP.NET")

    msgMail.BodyFormat = MailFormat.Text
    msgMail.Body = Message
    'SmtpMail.SmtpServer = "mail.the-radiator.com"
    SmtpMail.SmtpServer = "localhost"
    SmtpMail.Send(msgMail)

End Sub

I added this section in my web.config but that does not make a difference

<system.net>
    <mailSettings>
        <smtp>
            <network host="relay.tagadab.com" port="25" />
        </smtp>
     </mailSettings>
</system.net>

解决方案

Web.Config file:

<configuration>
 <system.net>
        <mailSettings>
            <smtp from="yourmail@gmail.com">
                <network host="smtp.gmail.com" 
                 port="587" 
                 userName="yourmail@gmail.com" 
                 password="yourpassword" 
                 enableSsl="true"/>
            </smtp>
        </mailSettings>
</system.net>
</configuration>

这篇关于如何在 web.config 中配置 SMTP 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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