rum*_*umi 30 .net vb.net asp.net smtp email-integration
我正在尝试修复继承网站的电子邮件问题,并且无法访问代码(即只编译文件).此站点需要托管在具有不同smtp服务器的新Web服务器上.
反编译代码后,我可以看到电子邮件使用下面的方法在代码片段中发送,smtp设置为smtpMail.SmtpServer ="localhost"但我的新网络服务器的smtp服务器是"relay.tagadab.com"我们怎么可能配置这在web.config中,以便localhost被视为"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
Run Code Online (Sandbox Code Playgroud)
我在我的web.config中添加了这一部分,但这并没有什么区别
<system.net>
<mailSettings>
<smtp>
<network host="relay.tagadab.com" port="25" />
</smtp>
</mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)
小智 65
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>
Run Code Online (Sandbox Code Playgroud)
我没有足够的代表来回答ClintEastwood,并且接受的答案对于Web.config文件是正确的.添加此代码以获得代码差异.
在Web.config上设置mailSettings时,除了新建SmtpClient和.Send之外,您不需要做任何其他事情.它无需引用即可找到连接本身.你会改变你的C#:
SmtpClient smtpClient = new SmtpClient("smtp.sender.you", Convert.ToInt32(587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password");
smtpClient.Credentials = credentials;
smtpClient.Send(msgMail);
Run Code Online (Sandbox Code Playgroud)
对此:
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(msgMail);
Run Code Online (Sandbox Code Playgroud)
设置 IIS 以将您的邮件转发到远程服务器。具体取决于 IIS 的版本。对于 IIS 7.5:
归档时间: |
|
查看次数: |
89647 次 |
最近记录: |