I'm using GmailApp/MailApp to send notification emails, and I want to bcc my self using an "address alias", but no email is delivered to my gmail.
Example:
Email is sent to someone#somedomain.com <- Works
BCC is sent to mygmailacct+notifications#gmail.com <- Does not work
If I remove the "address alias" from my BCC, it works;
BCC is sent to mygmailacct#gmail.com <- Works
However this means I can't filter the notifications properly etc.
Sending an email to mygmailacct+notifications#gmail.com from some other email account works fine as expected.
Code:
function sendEmail(to, subject, body) {
// Default options
var options = {
name: 'System notifications',
bcc: 'gmail.accnt+notification#gmail.com'
};
MailApp.sendEmail(to, subject, body, options);
}
Rule:
Matches: to:(mygmailacct+notifications#gmail.com)
Do this: Apply label "notifications", Never send it to Spam, Mark it as important
Your code looks okay, It is probably skipping your inbox, try looking in All Mail or Sent Mail
To prevent clutter, Gmail doesn't route messages that you send to your
own alias to your inbox. You can find the message in Sent Mail or All
Mail. If you need to see messages sent to your alias in the Inbox, you
can configure the alias as an alternate "Send mail as" address for
your account.
— Source
Related
Scenario
Create a script that can send a email as per user selection on google spread sheet.
When user going to send email first time in a day must send a new email.
If going to send second time check subject line if already exists then must be replyAll to that email.
Attempted code
if (threads[0]) {
threads[0].replyAll(emailBody, {
// 'replyTo': emailAddress, (Removed due to issue with Gmail)
'cc': emailAddressCC,
'bcc': emailAddressBCC,
'htmlBody': emailBody
});
} else {
MailApp.sendEmail(emailAddress, subject, emailBody, {
// 'replyTo': emailAddress,
'cc': emailAddressCC,
'bcc': emailAddressBCC,
'htmlBody': emailBody
}
Link to full script: GitHub
This script creates a menu onOpen "Send Mail".
So, when user selects some area from sheet and click on "Send Mail" button it calls funShowAlert() and sends an email.
Issue
When I attempt to add the recipient's email to replyTo, gmail returns an error.
Question: Is it possible to use replyAll without the replyTo option parameter, and am I doing something wrong with replyTo ?
I am doing something wrong with replyTo ?
Yes.
Read the documentation carefully:
Reply to the sender (using the replyTo address),
The 'replyTo address' here is referring to the replyTo address in the email to which are you replying. It is made apparent that this is NOT the replyTo option parameter by the fact that there is no such parameter passed in the example immediately following it.
replyTo as a parameter option is defined in the next entry:
an email address to use as the default reply-to address (default: the user's email address)
'The user' here being the user the script is running as. This means that the replyTo option should be the address you would want the recipient to reply to. Normally when sending via Gmail's web UI, this must be a Gmail Alias associated with that account; although some testing with Apps Script indicates that is not necessarily the case.
Your code as is, with replyTo removed, is sufficient.
I'm creating a script with Google Script to perform a multiple email send with personalized text inside the email body (like name and addresses).
Is it possible to send the emails with an imported account (in GMail) via script?
Thanks
You can use send method of GmailApp:
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendemailrecipient-subject-body
sendEmail(recipient, subject, body)
Sends an email message. The size of the email (including headers) may not exceed 20KB.
// The code below will send an email with the current date an time
var now = new Date();
GmailApp.sendEmail("mikemike#gmail.com", "current time", "The time is: " + now.toString());
Also, GmailApp.sendEmail support send from your alias as well.
sendEmail(recipient, subject, body, options) support use options to set options.from = 'alias#domain.com', as document saying:
from: String, the address that the email should be sent from, which must be one of the values returned by getAliases()
When sending mail using MailApp.sendEmail() or GmailApp.sendEmail() from App Script to a non-existent address I do not get an email informing about the error. I would expect an email to the account that sends reporting problem: 550 recipient rejected.
function testNonExistentAddress() {
var _recipient = 'nonexistentaddress#myexample.net';
var _subject = 'TEST FROM MAILAPP APPSCRIPT';
var _body = 'TEST';
MailApp.sendEmail(_recipient, _subject, _body);
}
The problem is that it is not sending it from you. It's simply bouncing it off a Google server. You will also notice that it doesn't appear in your sent folder, and that you need to declare who the email is coming from. I also bcc myself on the emails that my apps send so that I have a record in my mail account.
Nothing to be done, I believe. Other than checking the issue tracker / feature request. Or calling a third party system to ensure that the email address is real.
I have several scripts in Google Docs spreadsheets that use MailApp.sendEmail to send e-mails incorporating data from the spreadsheets. They've all worked marvelously for years. About 2 weeks ago, they stopped sending the e-mails. The scripts still run and I don't get any errors. The e-mails just never come through. Nothing has changed, except that the e-mails aren't arriving anymore.
Any thoughts?
Thanks!
I think I have an answer to my own question, which may be helpful to anybody else who has this problem. MailApp.sendEmail DOES, indeed, still seem to be working. What has changed is the way Gmail is handling certain types of messages.
If I use MailApp.sendEmail to send an e-mail to a third party, it'll get through, no problem. As pointed out by Fashtas, if I use MailApp.sendEmail to send an e-mail to the Gmail account that the spreadsheet belongs to, no problem.
Here's the problem: if I use MailApp.sendEmail to send the message to a third party account that automatically forwards BACK to the Gmail account that the spreadsheet belongs to, those messages no longer get through.
Therefore, in the sample code I posted above, the matt#.com e-mail address automatically forwards back to my Gmail account. The messages sent by the MailApp.sendEmail make it through to the .com mail server, but for some reason, they don't get forwarded back to my Gmail inbox. They appear in the Gmail Sent Items folder (presumably because they were sent by the Gmail account that the spreadsheet belongs to), but they never hit the inbox.
That behavior is new. In the past, there has been no problem with those messages getting forwarded from the *.com server to my Gmail inbox. I don't know what changed to cause the problem. And I don't know how to fix it.
But I, therefore, think the answer to my question is that MailApp.sendEmail IS working as designed.
As explained by doebtown, MailApp.sendEmail() will refuse to send messages to any address that forwards to your account. For example, if you (the spreadsheet's owner) belong to a group, people#myorg.com, within your organization then mailApp.sendEmail() messages will not be delivered to people#myorg.com. That is, the following code will not send:
var email = 'people#myorg.com';
var subject = 'The Week Ahead';
var body = 'Hi there!';
var htmlbody = "<p>Hi there!</p>";
// this will not send
MailApp.sendEmail(email, subject, body,{
htmlBody : htmlbody
});
HOWEVER, you can work around this issue by appending your email to the addresses.
var email = 'myaddress#myorg.com, people#myorg.com';
var subject = 'The Week Ahead';
var body = 'Hi there!';
var htmlbody = "<p>Hi there!</p>";
// this will send to your address and the full list
MailApp.sendEmail(email, subject, body,{
htmlBody : htmlbody
});
This email will send to your address as well as to the list to which you belong. This is not a perfect solution, but is viable if you do not want to create a specific account for managing scripts.
You can apparently only send emails to the gmail/email account the spreadsheet belongs to.
There are multiple ways to send an email through Google App Scripts.
MailApp: Traditional method, however I could not get a single email to send. Introduction course here.
GmailApp: Same method as MailApp however using the below code worked to send emails.
GmailApp.sendEmail(emailList[index], "New email", "New email", {"cc":"XXXXXXX#gmail.com"});
Add a the Gmail API through Services. This options was not explored but documentation can be found here.
Conclusion: Don't use the MailApp, instead use GmailApp.
Here's my Google App Script code:
var messages = threads[x].getMessages();
for (var y in messages)
{
messages[y].forward("someone#example.com");
}
This forwards fine, but it resets the from field of message to the email id of account which executes the script. This removes all credentials of the original sender of message. How to forward the email more elegantly such that all original headers (at least from and to) are retained? If the original message was sent to a list of people or a newsgroup, I need to retain it in the forwarded message.
In general a forwarded email does not retain the original from and to address. If you forward an email using GMail or Outlook you'll notice this. The GMailApp is behaving the same way.