title: ASP.NET Identity UserManager IIdentityMessageService pass extra parameters to SendAsync
body: <p>I've successfully created custom email service provider for UserManager by extending <code>IIdentityMessageService</code>:</p>
  
  <pre><code>public class ExchangeEmailService : IIdentityMessageService
  {
      public async Task SendAsync(IdentityMessage message)
      {
          using (var client = new SmtpClient())
          {
              client.Host = "mail.example.com";
              client.DeliveryMethod = SmtpDeliveryMethod.Network;
              client.UseDefaultCredentials = false;
              client.Credentials = new NetworkCredential(@"noreply", "P@ssw0rd");
  
              var from = new MailAddress("no-reply@example.com");
              var to = new MailAddress(message.Destination);
  
              var mailMessage = new MailMessage(from, to)
              {
                  Subject = message.Subject,
                  Body = message.Body,
                  IsBodyHtml = true
              };
              await client.SendMailAsync(mailMessage);
          }
      }
  }
  </code></pre>
  
  <p>Inside <code>UserManager</code>'s Create I'm creating new instance of my service and assigning it to <code>EmailService</code>:</p>
  
  <pre><code>userManager.EmailService = new ExchangeEmailService();
  </code></pre>
  
  <p>This all works fine, but I have requirement to send emails from different email addresses, based on place this is called from, unfortunately <code>UserManager.SendEmailAsync</code> isn't allowing me to pass anything except userId, subject and body.</p>
  
  <p>Ideally I'd like to be able to specify email address when calling <code>SendEmailAcync</code> or enum value.</p>
  
  <p>I've searched in <a href="https://aspnetidentity.codeplex.com/SourceControl/latest#src/Microsoft.AspNet.Identity.Core/UserManager.cs" rel="nofollow noreferrer">UserManager source</a> and I thought about creating custom <code>SendEmailAsync</code> implementation, but I'd have to change multiple places - IIdentityMessageService, UserManager.</p>
  
  <p>I know I can create new interface and build my email sending class on it, but I'd like to keep changes to minimum.</p>
  
  <p>What I'd like to get:<br>
  I'd like to have enum containing names of mailboxes:</p>
  
  <pre><code>public enum Mailboxes
  {
      Noreply = 0,
      Service = 1,
      Contact = 2
  }
  </code></pre>
  
  <p>and be able to call <code>SendEmailAsync</code> with that additional parameter:</p>
  
  <pre><code>await UserManager.SendEmailAsync(user.Id, "Account created", "Nice email content.", Mailboxes.Noreply );
  </code></pre>
  
  <p>I'm aware that I can set different title and use same email address, but this is requirement I got.</p>
  
  <p>How can I do that?</p>