As of yesterday, Nov 10th 2016, my google script stopped working with the following error msg.:
Invalid argument: info#mydomain.ch (line 168, file "Code")
The line in question looks like this:
GmailApp.sendEmail("someone#theirdomain.com",
"Subject title",
"", {
from: "mrbob#mydomain.com",
name: "Mr. Bob",
htmlBody:
"Hello, <br><br> Bla blah blah... <br> Cheers,<br> Mr. Bob"
});
My email address (mrbob#mydomain.com) is set up to 'send mail as' in my gmail account. It is not an alias. The function in my code has been working well for the past year, so I don't know why it has suddenly stopped. Any ideas and solutions?
It's quite important that the from address be this one rather than my gmail address.
Google has recently made some changes in the MailApp / GmailApp service and you can now only send emails from accounts that are set as "aliases" in your main Gmail account.
Go to Gmail -> Settings -> Accounts and ensure that "set as alias" is written against the email address that you are using to send emails in the Google Script.
as of today (June 2017) The opposite of Karl_S response worked for me. I was using MailApp.sendmail(...)
I changed to
GmailApp.sendEmail('to#email.com', 'subject', 'message', {'from':'aliasinmyGmailaccount#otherdomain.com'})
and it worked.
this is the current documentation:
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String,Object)
Try running the code from the editor with either the Run or Debug menu item. I have recently had a few scripts that have needed me to re-accept permissions. I have not looked into it to see if additional access is needed.
My emails are sending with this:
MailApp.sendEmail({
to: sendToEmailAddress,
bcc: emailAddressCC,
replyTo: emailAddressReplyTo,
name: emailFromName,
subject: emailSubjectText,
body: emailText,
htmlBody: emailHTMLBody
});
Can you try the MailApp class instead. From the documentation page:
This service allows users to send emails with complete control over
the content of the email. Unlike GmailApp, MailApp's sole purpose is
sending email. MailApp cannot access a user's Gmail inbox.
Changes to scripts written using GmailApp are more likely to trigger a
re-authorization request from a user than MailApp scripts.
Related
I have a budget sheet, which need to be populated in africa, by people without a google account.
I share the google sheet via a link and they can update the content. When they finished the updating, I would like to give them a possibility to send it to a small distribution list via a script
function sendReport() {
var message = {
to: "user#domain.org",
subject: "Budget proposal",
body: "Hi team,\n\nPlease find the budget attached.\n\nThank you,\n",
name: "Budget",
From: 'user#gmail.com',
attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("Budget")]
}
MailApp.sendEmail(message);
}
This works fine as long as I m logged in via any google account, but for a non google account, I get the following error:
Script sendReport experienced an error Details
The amount of data is too much for a form (but in a form I seem to be able to ask them to send a mail, so I wonder where I go wrong...
Thanks
MailApp.sendEmail(message) does not accept a From parameter, so that part of the object message gets ignored.
So if your account executes this script, you send it from your own domain email. Since it requires a google email to send a message, non-google accounts cannot execute this script.
Reference:
MailApp.sendEmail
I have tested a Google Apps script to send a google doc converted to PDF by mail automatically. The email is sent to one email address at a time.
I tested this with my normal Gmail account and it worked fine.
But when I try to use it on my Gsuite account (professional mail), I get a "delivery failure" mail with this error inside it :
Message blocked
Message rejected. See https://support.google.com/mail/answer/69585 for more information.
After calling the google assistance, I activated the "allow unsafe application access". It's been 4 hours now since I've activated this option (the option says that it might take some time to get into effect), but the error is still there.
Do you know why such an error may be generated ?
The link provided in the delivery failure mail does not provide precise information about this mail, apart from general indications like maybe it's "spam", "the recipient does not exist", etc...
Such indications does not qualify with this mail because the fact is that I know it's usually working on my Gmail account. I don't know why it's blocked with the Gsuite account.
EDIT : When I send the same mail manually with the Gsuite account, with the same title, body and attachment, the mail goes through without any issue.
I have to point that I did not shared documents/sheets or the script between the two accounts (because it has generated weird script behavior in the past). I copy-pasted the documents and the scripts in my new Gsuite account. My Gsuite account is the only owner and has the only access to the documents and the script, without any sharing.
Here is the portion of the script used to send the automated email :
//recipientmail is defined elsewhere
//newPDFReportId is defined elsewhere
if (recipientmail !== null) {
MailApp.sendEmail(
recipientmail,
"EMAIL OBJECT",
"Hi !\r\rThis is an example of an automated mail.\r\r\rDon't hesitate to get in touch.\rThis is the alpha version of the email sender.",
{attachments: DriveApp.getFileById(newPDFReportId)})
}
I solved the delivery failure of the automated mail by using GmailApp instead of MailApp in my script.
I just wanted to know if this behaviour is normal. Is it suppose to send a copy of the mail to me as the script owner, as well as the intended recipient? For example this code:
function emailTest(){
MailApp.sendEmail("someemail#gmail.com","test subject","test body");
}
Will send out an email to someemail#gmail.com. I will also get a copy in my inbox as the script owner. Can I shut this off somehow?
Regards,
Shumway
Because you're sending the mail from your account, you'll see the message in your 'Sent' box. If you're seeing it in your Inbox, it's not related to the script itself, as this is only sending to "someemail#gmail.com".
Things to check:
You don't have a forwarding rule from "someemail#gmail.com" to your account.
You don't have a filter/mail client/ other service accessing your inbox and placing your sent mail in the inbox.
You're not looking at 'All Mail'. Etc, etc.
You can probably get help for this at: https://productforums.google.com/forum/#!categories/apps/mail-settings.
Okay this is very strange. I have scripting in a spreadsheet to take information from the currently active sheet, creates a report using a template file and sends it as an attachment.
This all works perfectly, when I use my Google apps domain account email address as the recipient. It doesn't work when I send to any other email address, other than my own. It was working yesterday. No errors generated when the script runs
The only thing that I did was change the owner of the spreadsheet to another user in our domain. It was shared with the other user while I was testing the scripts. I've tried using other email addresses in our domain and created a new spreadsheet with the sendemail function, all with the same behavior.
// Email the specified report
function emailReport(file, recipients, emailSubject, emailMessage) {
MailApp.sendEmail("someone#example.com", emailSubject, emailMessage,
{attachments: file, mimetype: 'application/pdf'});
}
I've been able to reproduce the problem and to find a workaround.
As it's not posible to send email to recipients without google account, I add that kind of emails on a cc field.
// Email the specified report as cc
function emailReport(file, recipients, emailSubject, emailMessage) {
MailApp.sendEmail("my#gmail.com", emailSubject, emailMessage,
{attachments: file, mimetype: 'application/pdf', cc:"someone#example.com"});
}
I noticed this question a while back, and even referenced it in another one. Since then I've noticed no one responded to you so...
It appears as if Google has recently changed (though not documented anywhere I've found) the MailApp.sendEmail function so that it only works when you use the email address belonging to the owner of the spread sheet.
My guess is this is to prevent the system being used for unsolicited mass emailing.
The other question was here
(Sorry, not an answer as such :( more of a confirmation as to what you are seeing seems to be as expected)
For anyone having this issue, use the GmailApp class instead of the MailApp class.
It supports the same functions, for example: GmailApp.sendMail('recipient#gmail.com', 'Subject', 'Message').
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)
I know there are some Mail Merge tools for Gmail. Are there any that allow me to use a registered "send from" address in gmail? When I set a different sending email within the two scripts here, it still sends from my default gmail account.
http://www.labnol.org/internet/personalized-mail-merge-in-gmail/20981/
As a developer, you can code a script to use any of the aliases available in a Google account as the "from" address. Here is a Google Apps Script documentation reference with an example (and copied below):
// The code below logs the aliases for this Gmail account and sends an email
// as the first one.
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(
"recipient#example.com", "subject", "body", {from: aliases[0]});
You might consider this App as a mail merge tool
http://www.thexs.ca/xsmerge
It's available in the Chrome web store (free)