Emails generated by Googleappscript are skipping my inbox - email

I have a shared google sheet that when someone enters their info it prompts the next individual with an email that's automatically generated by the script. These emails prompt a dozen individuals and show up as coming from my email. This has functioned perfectly for months.
In the past week or so I've stopped emails have stopped coming to my inbox. The still shows up in "Sent" and also under "All Mail" but I'm not sure if that's just the "sent" message". All other users receive emails normally. Also, if I change my target address to a different email it works fine. Basically, it appears i can't send myself an email.
I have recently started using email filters which I know is the most likely culprit in these situations. None of them currently use the "Skip Inbox" function.
I have no idea why these emails don't show up for me despite working for everyone else as well as if I enter an alternate email address.
Edit #1:
Below is the section of code that emails the next person. As stated it appears to be working perfectly because everyone else except myself gets an email. Also if I change my email to an alternate email that works as well. It appears the issue is solely when the script emails myself from the same email address.
Also, I noted that I was previously receiving emails. This may have been untrue. As a testing measure I previously "CC'd" myself with every email that went out so that I could track that the system was working well. You'll note in the code that my email address is stored in the variable "emailAddress2" and that the CC line has now been commented out. I may not have been receiving the actual email sent to myself before but actually only receiving the CC'd version.
Here's the code:
function emailNext (JustPickedName, NextToPickName, SelectedDate) {
// Function Sends emails to the next Person in the list
Logger.log("Into Email Next");
//Set all the Email characteristics
SelectedDate = Utilities.formatDate(new Date(SelectedDate), "GMT", "EEE, MMM d, yyyy"); //Format the Date for inclusion in the email
var StaffMember = StaffList.find(StaffList => StaffList.Name === NextToPickName);//Find Emails address by finding name in Emails Object
var subject = ' You have a pick pending in the ' + ActiveWeekSheetName + ' sheet';
var message =
'<p>Dear Dr. ' + NextToPickName + '</p>' +
'<p>You have a pick pending on ' + SelectedDate + '. Please look at the ' + ActiveWeekSheetName + ' sheet.</p> <p> Dr. ' + JustPickedName + ' has just made a pick and you are up.</p>' +
'<p>You can make your selection here: GGH Room Selection</p>';
MailApp.sendEmail({
to: StaffMember.Email,
//bcc: emailAddress2,
name: 'PickListBot',
subject: subject,
htmlBody: message})
Logger.log("StaffMember.Email: " + StaffMember.Email);
}

What you are describing might in fact be a bug.
Since this is the case, I suggest you check this issue here on Google's Issue Tracker and star it in order to get any updates with regards to it.

Related

how can I force Google App Script MailApp.sendEmail to use a new thread for each email in a loop?

I am doing a simple app, I have an spread sheet with a few columns, one is an email addres and the others are filled with the information I want to send in an email to that addres. The code is really simple, it is just a while loop with the execution of MailApp.sendEmail with the data in each row.
The issue that I am having is that when I execute the app all the emails end up in the same email threard. And this makes really difficult to follow the responses beacause each email is independet. I've been looking for a while on how to force MailApp.sendEmail to start a new thread, but I can't find how to do it in the documentation or in the web.
The issue is that you are using the exact same subject for these emails and therefore they end up in the same email thread.
For example:
This will put all the emails in the same thread:
function myFunction() {
for (let i=0; i<2; i++){
MailApp.sendEmail("example#gmail.com",
"Test", // subject is the same for every email
"This is an test email");
}
}
This will put the emails in different threads:
function myFunction() {
for (let i=0; i<2; i++){
MailApp.sendEmail("example#gmail.com",
"Test"+i, // subject is different for every email
"This is an test email");
}
}
Instead of using i which is not very well descriptive as a subject, you could send the datetime:
"Test"+new Date()
although this might not work if the emails are sent instantly and therefore the subject will be the same again, but it might work in your case.
Ideally, you would want something that is relevant to the email, for example relevant to the body of your email.

If/Else Loop and Auto Email

New to coding and trying to jump right in!
I have a new list of customers I'm responsible for in a spreadsheet, and I receive an email from someone I don't immediately recognize.
I need to set up a script to:
1. determine if they are in my book of business
2. if they are in my book of business, send a template email regarding next steps (email A)
3. if they are not in my book of business, send a template email that i'm not their POC and redirecting them to relevant resources (email B)
I believe I need to set up a loop (if/else?) to see if the email I received is from a sender on the list, if it is, send email a, if it isn't send email b.
Does anyone have feedback on my stab below? I've set up a dumbie example I will constantly be working on and updating. https://docs.google.com/spreadsheets/d/1HcLluPhRgl0ihQT0GA-ZFj1KsOPHxl0dU08EFlh2Gss/edit#gid=0
For the if/else I believe I would start with
if (CustomerName) {exists Send email A
} else {Send Email B
}
// The code below will send an email with the current date and time.
var now = new Date();
GmailApp.sendEmail("jlennon#gmail.com", "current time", "The time is: " + now.toString());

Google Script email also being sent to account owner?

I have a problem with a Google MCC Script I have. It's set up to run every day in the early hours of the morning, do some processing, and email out a result, using Google Scripts' built in MailApp.sendEmail function.
The problem is that, while the email is sent successfully, I'm also recieving messages in the inbox of the email address which owns the MCC account along the lines of
Delivery to the following recipient failed permanently:
MCC_account#example.com
Technical details of permanent failure: The email account that you
tried to reach does not exist. Please try double-checking the
recipient's email address for typos or unnecessary spaces.
with the 'Original Message' appended below that indicating it is indeed the message the Script has sent. Here's my code:
function main() {
var accountSelector = MccApp.accounts();
var accountIterator = accountSelector.withIds('###-###-###').get();
if(accountIterator.hasNext()){
var account = accountIterator.next();
MccApp.select(account);
var data = getData();
sendEmail(data);
} else Logger.log("Error: no accounts found");
}
function sendEmail(data){
var name = 'name';
var bodytext = 'body';
MailApp.sendEmail({
to: 'receiver-inbox#example.com',
name: 'Google Adwords Scripts',
replyTo: 'do-not-reply#example.com',
subject: 'SUBJECT',
attachments: [{fileName: name, mimeType: 'text/csv', content: data}],
body: bodytext
});
}
So, to clarify, the MCC account is owned by one email address, the script doesn't reference that at all, but I'm recieving the email not only in the target mailbox but also a failed delivery message in the owner inbox.
Can anyone shed any light on what is happening here?
It is very likely that you are running another copy of the script that is sending these emails. Go to your Google Account settings here and revoke access to the other script.
If you have multiple Google accounts, do a scan for all the accounts.
Okay, apparently this is a known issue with AdWords Scripts:
https://groups.google.com/forum/#!topic/adwords-scripts/SJtNW_wuArI

Undefined e.values on google email notifications

I am using script editor in google spreadsheets to send an auto response email. However, I received Summary of failures notifications suggesting an invalid email: undefined (on the Mail.App line). I don't know how this error came about. Please help. Thanks so much.
function myFunction(e) {
var Nickname = e.values [2];
var email = e.values [10];
var subject = "Form Submitted"
var message =
"Thank you, " = + Nickname + ". Your response is accepted. You may want to check our website # iydsphilippines.weebly.com for registration payment details. Thanks and we hope to see you soon!";
MailApp.sendEmail(email, subject, message);
}
Here is a link to a copy of my spreadsheet.
<>
I'm no expert however I also had the same issue and by trial and error I have discovered what the problem is.
It seems that recently Google have "upgraded / changed" the way fields are evaluated.
If any fields are blank then problems arise and as your email field in column K (i.e. the 10th field counting the first as zero) and some of the others are blank it seems to get confused. Until Google fix this "undocumented feature" I have a workaround.
Move your Email column to nearer the beginning i.e. straight after the name for example but before any optional fields, then renumber it in the code and you should be OK.
Specifically in your example: Move Column K to be Column C and renumber "var email = e.values [10]" to be "var email = e.values [2]" That should do it.
Good Luck and let me know how you get on. From Lester in the UK

How to monitor delivery of emails sent by salesforce by source code?

I have following questions. Assuming I have following code
public class MessageMaker {
public static void helloMessage() {
System.debug( 'Entry point' );
Case c = new Case();
insert c;
EmailMessage e = new EmailMessage();
System.debug( 'EmailMessage created' );
e.parentid = c.id;
// Set to draft status.
// This status is required
// for sendEmailMessage().
e.Status = '5';
e.TextBody =
'Sample email message.';
e.Subject = 'Apex sample';
e.ToAddress = 'my#mail.com';
insert e;
List<Messaging.SendEmailResult>
results =
Messaging.sendEmailMessage(new ID[]
{ e.id });
System.debug(results.size());
System.debug(results[0].success);
System.debug(results[0].getErrors().size());
System.assertEquals(1, results.size());
System.assertEquals(true, results[0].success);
}
}
1.First question. I want to find out using apex code if the message was really delivered.
Here documentation says http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail_emailresult.htm
Even if success = true, it does not mean the intended recipients received the email, as it could have bounced or been blocked by a spam blocker. Also, even if the email is successfully accepted for delivery by the message transfer agent, there can still be errors in the error array related to individual addresses within the email.
So I have been trying to send email by apex code and look for results[0].success. It seems it says like it is described in documentation, so success is true even though email address was incorrect.
Also I have tried to check this manually through email logs http://eu2.salesforce.com/help/doc/en/email_logs.htm
And I have found following row in resulting log regarding my email sent to incorrect address
9/2/2013 9:36 66/FC-09306-20B54225 T julfy#i.ia
julfy=i.ua__0-6uvic1ltvun1nf#95mngihd2hpe0w.b-ysubea0.bl.bnc.salesforce.com 1434 005b0000000J7bm
<_0vTJ000000000000000000000000000000000000000000000MSHRSY00W1-CKg3DShWC5xu24ccHFA#sfdc.net>
1 311.627583 421 4.4.0 [internal] no MXs for this domain could be
reached at this time
But I don't know how to access this information by apex code. Any thoughts?
Second question. If message was delivered and recipient forwarded it, is any possibility to monitor that using apex code? Anybody?
You can't do either of those things. APEX runs on Salesforce's servers and when you send an email it leaves that environment. The only time you can monitor a successful response is when you're dealing with an API that generates webhooks.