6

I am trying to send an email through code, and I ran into a roadblock. I was working off of this when Base64UrlEncode showed up red. I have the same using statements in my code.

using System;
using System.IO;
using System.Net.Mail;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MyCompany.Sample.EmailConnector.Model;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Gmail.v1;
using Google.Apis.Gmail.v1.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
...
    public static Message createGmailMessage(AE.Net.Mail.MailMessage mailMessage)
    {
        var messageString = new StringWriter();
        mailMessage.Save(messageString);
        Message gmailMessage = new Message();
        gmailMessage.Raw = Base64UrlEncode(messageString.ToString());
    }

How do I enable the "Base64UrlEncode"?

Chris
  • 28,822
  • 27
  • 83
  • 158

1 Answers1

15

"Base64UrlEncode" is just a custom function:

private static string Base64UrlEncode(string input) {
    var inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
    // Special "url-safe" base64 encode.
    return Convert.ToBase64String(inputBytes)
      .Replace('+', '-')
      .Replace('/', '_')
      .Replace("=", "");
  }
Tholle
  • 108,070
  • 19
  • 198
  • 189
  • 1
    yeah, realized that after I posted. No wonder I couldn't find it. Would delete if I could. – Chris May 14 '15 at 20:24
  • 3
    I actually added the Microsoft.IdentityModel.Tokens package from NuGet https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/master/src/Microsoft.IdentityModel.Tokens/Base64UrlEncoder.cs – Laki Politis Mar 07 '17 at 07:21