如何在POSTAL MVC中而不在WEB.Config中设置SMTP客户端 [英] How to Set SMTP Client in POSTAL MVC not in WEB.Config
本文介绍了如何在POSTAL MVC中而不在WEB.Config中设置SMTP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目中使用POSTAL MVC时出现问题.我的托管服务公司要求我使用不在Web配置中的代码来设置smtp客户端配置.
i have a problem when using POSTAL MVC in my Project. My hosting services company requires me to set smtp client config in code not in web config.
该怎么做?
我希望有人能给我解决方案
I hope someone can give me a solution
谢谢.
推荐答案
我遇到了同样的问题.没有官方的邮政文件上的参考,也没有使用方法. 所以这里是一个:
I had the same problem. There is no reference on the official Postal documentation, nor an How-to. So here goes one:
- 使用自定义配置创建SmtpClient实例
- 使用带有2个参数(ViewEngineCollection,Func«SmtpClient»)的构造函数创建一个Postal.EmailService实例
- 现在,您可以通过调用emailService使用自定义SmtpClient配置发送电子邮件.
这里有完整的示例代码:
Here goes a complete sample code:
dynamic email = new Email("Example");
email.To = "webninja@example.com";
email.FunnyLink = DB.GetRandomLolcatLink();
SmtpClient client = new SmtpClient("mail.domain.com");
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("user@domain.pt", "somepassword");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.EnableSsl = false;
Postal.EmailService emailService = new Postal.EmailService(new ViewEngineCollection(), () => client);
emailService.Send(email);
这篇关于如何在POSTAL MVC中而不在WEB.Config中设置SMTP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文