Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVCMailer smtp mailsettings set configuration settings programmatically

MVCMailer uses the smtp settings from the web.config file as follows:

<system.net>
<mailSettings>
      <smtp from="[email protected]">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="valid-password" />
      </smtp>
</mailSettings>
</system.net>

Controller:

public virtual MvcMailMessage Welcome()
{
    //ViewBag.Data = someObject;
    return Populate(x => {
              x.ViewName = "Welcome";
              x.To.Add("[email protected]");
              x.Subject = "Welcome";
        });
}

Is there anyway to set the SMTP settings in code? I want to avoid saving the password in the web.config file.

like image 972
woggles Avatar asked Jan 04 '13 12:01

woggles


1 Answers

Call SmtpClientWrapper with a SmtpClient that has the properties you need.

SmtpClient client = new SmtpClient("mail.example.com", 995);
SmtpClientWrapper wrapper = new SmtpClientWrapper(client);
like image 105
jao Avatar answered Nov 15 '22 00:11

jao