alex
alex

Reputation: 55

ActionMailer MVC - Set multiple SMTP, Email Sender in webconfig OR in C#

I would like to use multiple sender's email (smtp) for different cases with actionmailer MVC.

For example, if it's a new user registering, then the confirmation will be sent with the [email protected] email.

If the user get contact by another user, the sender email will be [email protected].

So I need to setup 3-4 smtp, and use them in actionmailer. So far, webconfig can't support multiple smtp. Thks

Upvotes: 0

Views: 1575

Answers (1)

Steven V
Steven V

Reputation: 16595

MailerBase has a property From available (among others) that you can set in C# depending on whatever logic you use. Then combine that with <appSettings> from the web.config you can do something like:

<appSettings>
    <add key="RegistrationFromAddress" value="[email protected]" />
    <add key="ContactFromAddress" value="[email protected]" />
</appSettings>

then in your controller

public class MailController : MailerBase
{
    public EmailResult RegisterEmail()
    {
        From = System.Configuration.ConfigurationManager.AppSettings["RegistrationFrom"]; // or ContactFromAddress if you want
    }
}

Upvotes: 1

Related Questions