From 74546f6ef0e0bacb319bcc6d6f4f5be9a5f8dd2e Mon Sep 17 00:00:00 2001 From: Ryan Schlesinger Date: Thu, 22 Aug 2019 09:43:10 -0700 Subject: [PATCH] Use upload_source when attachments are present --- lib/google_http_actionmailer.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/google_http_actionmailer.rb b/lib/google_http_actionmailer.rb index 6a5ce76..637feaf 100644 --- a/lib/google_http_actionmailer.rb +++ b/lib/google_http_actionmailer.rb @@ -32,10 +32,20 @@ def initialize(params) def deliver!(mail) user_id = message_options[:user_id] || 'me' - message = Google::Apis::GmailV1::Message.new( - raw: mail.to_s, - thread_id: mail['Thread-ID'].to_s - ) + + message = nil + if mail.attachments.empty? + message = Google::Apis::GmailV1::Message.new( + raw: mail.to_s, + thread_id: mail['Thread-ID'].to_s + ) + else + message = Google::Apis::GmailV1::Message.new( + thread_id: mail['Thread-ID'].to_s + ) + message_options[:upload_source] = StringIO.new(mail.to_s) + message_options[:content_type] = 'message/rfc822' + end before_send = delivery_options[:before_send] if before_send && before_send.respond_to?(:call)