Using the Gmail Service to send an email, but I'm having problem with the email format which needs to be passed to Google::Apis::GmailV1::Message
, I'm passing raw parameter to it in the following format
email_raw = "From: <#{@google_account}>
To: <#{send_to}>
Subject: This is the email subject
The email body text goes here"
# raw is: The entire email message in an RFC 2822 formatted and base64url encoded string.
message_to_send = Google::Apis::GmailV1::Message.new(raw: Base64.encode64(email_raw))
response = @service.send_user_message("me", message_to_send)
This fails even when I pass email_raw
without base64 encoding. I'm providing valid emails but it fails with an error
Google::Apis::ClientError (invalidArgument: Recipient address required)
I've checked Sending an email with ruby gmail api v0.9 and I also found this but it uses Mail
class which I could not locate in the Gmail API Ruby client library. Currently, email_raw
contains \n
characters but I've tested it without it and it doesn't work.
Moreover, I also want to send attachments in a message.