• About Morris Development
  • A Focus for Cloud Efficiency
    • Microsoft Azure
    • Amazon Web Services
  • What our Clients Say
  • Our Products
    • PreschoolDB
    • WebinarDB
  • Contact Us

Morris Development

Custom System Development and Integration

May 6, 2020

Sending large emails with Gmail API

I’m only writing this note because I’ve literally been working on this for 4 hours and there’s zero documentation.

If you want to send an email with attachments that’s more than ~5mb using the .Net Gmail API, you’re out of luck…. but not really. It’s actually EASIER. I don’t know why in the heck they decided to do this, but here’s the code:

  MimeKit.MimeMessage mimeMessage = MimeMessage.CreateFromMailMessage(msg);
           
            MemoryStream stream = new MemoryStream();
            mimeMessage.WriteTo(stream);
            stream.Position = 0;

            var message1 = new Google.Apis.Gmail.v1.Data.Message();

            try
            {
                var email2 = await service.Users.Messages.Send(message1, msg.From.Address, stream, "message/rfc822").UploadAsync();
                return email2.Status.ToString();
            }
            catch (Exception e)
            {
                return e.Message;
            }

Instead of sending it raw and doing all that idiotic conversion, you just make your mime message and push it as a stream using “Upload” instead of “Execute”. Seriously. WTF? There are about 1000000 examples of the Execute() version, but I couldn’t find a single one of the Upload().

Hours and Hours of wasted time.

I hope this saves someone a few minutes.

Article by MacGyver / Angular 2

About MacGyver

I've worked with database systems for over 20 years, and started my own company in 2000. Almost all my business consists of internal database systems, either ERP or CRM. My programming is primarily in Angular / Microsoft C# and MS SQL.

About This Site

Morris Development has been specializing in internal database system design and integration since 1999. We provide long-term management and support of secure data systems for many businesses as well as developing the more complex code structures for ERP systems like Intellievent, Apidas, and AVMS.

This site is primarily for our developers to keep track up various technologies and updates that are used by Morris Development.

Training

Integrating Angular Microsite with .Net

Private Data Caching with Google Storage

Continuous Deployment for Production Releases?

Azure Websites – the perfect Angular host

Angular 2

  • Angular 2 Authentication
  • Angular Command Line Interface
  • Material Design for Angular
  • Using Observables in Angular 2

Mentors

  • Ben Nadel
  • Dan Wahlin
  • Deborah Kurata
  • John Papa

Staff

  • Dan Morris

Training

  • Google Development Courses
  • Microsoft Virtual Academy
  • PluralSight
  • Test Deep Links

© 2025 · Morris Development