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.
Call SmtpClientWrapper
with a SmtpClient that has the properties you need.
SmtpClient client = new SmtpClient("mail.example.com", 995);
SmtpClientWrapper wrapper = new SmtpClientWrapper(client);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With