title: Add account activation url from Microsoft Identity to SendGrid email dynamic templates - ASP .NET
body: <p>I created an Asp.net project and added Identity. I want to use SendGrid dynamic email templates (not the LegacyTemplates) for account confirmation. Basically, <strong>I want to insert the tokens generated by the microsoft idendity on a button in the SendGrid template</strong>. How can I do that?</p>
  <p>Here's my code:</p>
  <pre><code>public EmailSender(IOptions&lt;AuthMessageSenderOptions&gt; optionsAccessor)
          {
              Options = optionsAccessor.Value;
          }
  
          public AuthMessageSenderOptions Options { get; }
  
          public Task SendEmailAsync(string email, string subject, string message)
          {
              return Execute(Options.SendGridKey, subject, message, email);
          }
  
          public Task Execute(string apiKey, string subject, string message, string email)
          {
              apiKey = &quot;api key&quot;;
              var client = new SendGridClient(apiKey);
              var msg = new SendGridMessage()
              {
                  From = new EmailAddress(&quot;my email&quot;, Options.SendGridUser),
                  Subject = subject,
                  PlainTextContent = message,
                  HtmlContent = message,
              };
  
              SetTemplateId(&quot;Template Code&quot;);
              msg.AddTo(new EmailAddress(email));
              msg.SetClickTracking(false, false);
  
              return client.SendEmailAsync(msg);
          }
  </code></pre>
  <p>The template:
  <a href="https://i.stack.imgur.com/aRq0c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aRq0c.png" alt="enter image description here" /></a></p>