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

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

问题描述

我正在尝试解决与继承的网站有关的电子邮件问题,并且无法访问代码(即仅编译后的文件)。该站点需要托管在具有其他smtp服务器的新Web服务器上。

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.

在反编译代码时,我可以看到在代码段中使用以下方法发送电子邮件,并且smtp设置为smtpMail.SmtpServer = localhost,但是我的新Web服务器smtp服务器是 relay.tagadab.com,我们如何在web.config中进行配置,以便将本地主机作为 relay.tagadab.com

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

我在web.config bu中添加了此部分t没什么作用

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文件:

<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天全站免登陆