I don't believe this is specifically an MvcMailer question (this is the mailer I am using), but I am struggling with framing a Googleplex search to figure out how to send e-mails from different accounts based on my context.
I have a need to send two e-mails from two different e-mail accounts. I have tried using
mailMessage.From = new MailAddress("[email protected]");
in MvcMailer, but that doesn't even show up in the e-mail I dump to the temp directory. It shows up as what is in the web.config: "[email protected]".
This is my web.config for MvcMailer:
<mailSettings>
<!-- Method#1: Configure smtp server credentials -->
<!--<smtp from="[email protected]">
<network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="valid-password" />
</smtp>-->
<!-- Method#2: Dump emails to a local directory -->
<smtp from="[email protected]" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\" />
</smtp>
</mailSettings>
This is the mailer code:
public virtual MailMessage EMailConsultation(EMailConsultationData model)
{
var mailMessage = new MailMessage { Subject = "INQUIRY: E-Mail Consultation" };
mailMessage.From = new MailAddress("[email protected]");//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;
}
Again, the above code works to send e-mail. I just do not know how I can set up the mailer to send from a specified e-mail address, rather than just from "[email protected]" as is in the web.config. I have multiple MailMessages, and have a need to send certain ones from a different e-mail account.
I would greatly appreciate any help/code examples.