asp.net - 如何在web.config中配置smtp设置

标签 asp.net .net vb.net smtp email-integration

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

在对代码进行反编译后,我可以看到使用如下代码段中的方法发送电子邮件,并且将smtp设置为smtpMail.SmtpServer =“localhost”,但是我新的网络服务器的smtp服务器为“relay.tagadab.com”这在web.config中,以便将本地主机作为“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中添加了此部分,但这没有什么不同
 <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>

关于asp.net - 如何在web.config中配置smtp设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19233108/

相关文章:

c# - 使用 SevenZipSharp 压缩多卷?

c# - ASP.NET Razor Pages 检查属性验证状态?

.net - 从 Visual Studio 部署 .NET 应用程序以供公众使用的正确且完整的步骤是什么?

c# - 像 Stack Overflow 一样格式化数字(用 K 后缀四舍五入到千位)

c# - 你如何将对象从 c# 传递给 lua 的函数?

vb.net - 遍历特定数据表的行

asp.net - .Net 更改元素 ID

c# - 我的 C# 和 DLL 数据问题

c# - 'System.Net.ProtocolViolationException' {"You must write ContentLength bytes to the request stream before calling [Begin]GetResponse."}

mysql - VB.NET MySqlCommand 存储过程参数顺序?