asp.net-mvc-3 – 如何在web.config中设置不同的stmpclient实例
发布时间:2020-12-16 06:24:04 所属栏目:asp.Net 来源:网络整理
导读:我不相信这是一个专门的MvcMailer问题(这是我正在使用的邮件),但我正在努力构建Googleplex搜索,以找出如何根据我的上下文从不同帐户发送电子邮件. 我需要从两个不同的电子邮件帐户发送两封电子邮件.我试过用 mailMessage.From = new MailAddress("some-other
我不相信这是一个专门的MvcMailer问题(这是我正在使用的邮件),但我正在努力构建Googleplex搜索,以找出如何根据我的上下文从不同帐户发送电子邮件.
我需要从两个不同的电子邮件帐户发送两封电子邮件.我试过用 mailMessage.From = new MailAddress("some-other-email@gmail.com"); 在MvcMailer中,但这甚至没有显示在我转储到临时目录的电子邮件中.它显示为web.config中的内容:“some-email@gmail.com”. 这是我对MvcMailer的web.config: <mailSettings> <!-- Method#1: Configure smtp server credentials --> <!--<smtp from="some-email@gmail.com"> <network enableSsl="true" host="smtp.gmail.com" port="587" userName="some-email@gmail.com" password="valid-password" /> </smtp>--> <!-- Method#2: Dump emails to a local directory --> <smtp from="some-email@gmail.com" deliveryMethod="SpecifiedPickupDirectory"> <network host="localhost" /> <specifiedPickupDirectory pickupDirectoryLocation="c:temp" /> </smtp> </mailSettings> 这是邮件代码: public virtual MailMessage EMailConsultation(EMailConsultationData model) { var mailMessage = new MailMessage { Subject = "INQUIRY: E-Mail Consultation" }; mailMessage.From = new MailAddress("some-other-email@gmail.com");//I tested this to see if at the very least it would show up in the e-mail,but it didn't. mailMessage.To.Add(model.EMail); ViewData = new ViewDataDictionary(model); PopulateBody(mailMessage,viewName: "InquiryEMailConsultation"); return mailMessage; } 同样,上面的代码可以发送电子邮件.我只是不知道如何设置邮件程序从指定的电子邮件地址发送,而不是像web.config中的“some-email@gmail.com”那样.我有多个MailMessages,需要从不同的电子邮件帐户发送某些邮件. 我非常感谢任何帮助/代码示例. 解决方法
您可以在代码中创建自己的SmtpClient对象,并使用该对象发送生成的电子邮件.并且只在web.config中使用1个smtp设置(默认设置).
在您的web.config中为MvcMailer: <mailSettings> <smtp from="some-email@gmail.com" deliveryMethod="SpecifiedPickupDirectory"> <network host="localhost" /> <specifiedPickupDirectory pickupDirectoryLocation="c:temp" /> </smtp> </mailSettings> 并使用MyMailer.EMailConsultation().Send(); 如果您需要通过谷歌发送电子邮件(例如)使用此: using (var googleSmtp = new SmtpClient("smtp.gmail.com",587)) { googleSmtp.EnableSsl = true; googleSmtp.Credentials = new NetworkCredential("some-email@gmail.com","valid-password"); googleSmtp.Send(MyMailer.EMailConsultation()); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – ASP.Net MVC 3 ViewModel数据注释
- asp.net – Razor视图无法识别@model或Lambda @Html方法
- asp.net – Web Api参数始终为null
- asp.net – 请求在IIS工作进程中存在于RequestAcquireState
- asp.net-mvc – 允许使用ASP-MVC和表单身份验证访问特定页面
- 什么是ASP.NET应用程序部署的最佳实践
- asp.net-mvc-4 – ASP.NET MVC 4 – 从Controller添加Bundl
- .net – 如何使用LINQ创建IQueryable类型的匿名对象
- asp.net-mvc – 是否可以在Index视图中使用LabelFor作为标题
- asp.net – 如何解决错误:当应用程序未在UserInteractive模
推荐文章
站长推荐
- asp.net成员资格 – 在Application_Authenticati
- asp.net-mvc – 在ASP.NET MVC 3中使用WebGrid显
- asp.net-mvc – asp.net mvc中editortemplate中复
- ASP.net内联代码
- asp.net – RedirectToAction MVC2的问题 – 不能
- asp.net – 线程被中止
- active-directory – IdentityServer3 – 适用于
- asp.net-mvc – 覆盖控制器AuthorizeAttribute只
- asp.net – 在用户代码中未处理Assert faild异常
- asp.net-mvc – 如何在ASP.NET控制器中获取“Mvc
热点阅读