Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using statement for Base64UrlEncode [closed]

Tags:

c#

gmail-api

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"?

like image 954
Chris Avatar asked May 14 '15 20:05

Chris


1 Answers

"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("=", "");
  }
like image 115
Tholle Avatar answered Sep 28 '22 16:09

Tholle