How to change the email that sends the email of my google form script.
the form is accessible to 4 google accounts. I wrote it on mine. I want it to send from a different account, the one that is nobodies personal email.
Any idea?
for the record, this is, for the most part, the script
function generatePost(e){
var html = "hello";
// sends from my personal email
MailApp.sendEmail(e.values[7], ' ok!, ' + e.values[2], html,{htmlBody: html});
}
https://developers.google.com/apps-script/reference/mail/mail-app
It looks like you need to change the default replyTo address.
Look at the documentation on the function you're using: sendEmail(to, replyTo, subject, body)
The default of replyTo is "the user's email address". Just change it to a string of the email you want to use, i.e.:
sendEmail(e.values[7], "your_email#gmail.com", ' ok!, ' + e.values[2], html,{htmlBody: html})
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 have the following code attached to the OnBeforeDelete event in one of my data models in Google App Maker:
MailApp.sendEmail({
to: 'example#email.com',
cc: record.Resource.Manager.ManagerEmail ,
subject: 'Deleted Allocation',
body:
'February 2018: ' + record.February18 + '\n' +
'March 2018: ' + record.March18 + '\n' +
'April 2018: ' + record.April18
});
}
This code, and similar code like it, used to send emails correctly to both my personal Gmail account and an Outlook account. Now, however, they are only being received by my Gmail account. I tested again with a simpler function:
function myFunction() {
MailApp.sendEmail("example#email.com", "test mail", "why isnt this working");
}
Which confirms that it does not work when I type in the Outlook account instead of the placeholder email.
Does this only send email to Gmail accounts now (when it sent to Outlook earlier), or is there another explanation?
MailApp service does not have such restrictions; it can be used to send email to any address. Your test function myFunction worked as intended when I put in my (non-Gmail-related) email address in it.
If email is not being received, look for reasons on the receiving side. An overzealous spam filter may be to blame.
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()
Okay, so. I have written a simple script to send an email to anyone who completes my form on google docs. The problem is, i cannot get it to run, all i have is the guts to get the users email and send them an email. I have no means of launching the script. I have looked near and far trying to find a way to auto launch the script once the form is completed.
Tl;dr Trying to send a receipt confirming the form was completed.
here is the script:
function hallpassreceipt() {
// Get the email address of the active user - that's you.
var email = Session.getActiveUser().getEmail();
// Get the name of the document to use as an email subject line.
var subject = 'Hall Pass';
// Append a new string to the "url" variable to use as an email body.
var body = 'This is a hall pass .';
// Send yourself an email with a link to the document.
GmailApp.sendEmail(email, subject, body); }
Read Understanding Triggers.
You need to set up an Installable Form Response trigger. One example: Google Script to email form answers and questions to a user.
Romain Vialard and labnol did a great job with the scripting for a mail merge for gmail:
http://www.labnol.org/internet/personalized-mail-merge-in-gmail/20981
The script lets you indicate whether or not you want to be BCC'd on all the emails sent. It assumes the email address to include in BCC is the one you are sending from.
How can the script be changed to allow me to BCC a different email address, not just the one i'm sending from?
In other words, I want to be able to input any email address to BCC, such as "emailtosalesforce#n-xvh0q8 2w.31ghxkeac.3.le.salesforce.com"
Why:
I am a user of Salesforce.com, and one simple way to automatically log emails in the online system is to BCC an "Email To Salesforce.com" address, such as "emailtosalesforce#n-xvh0q8 2w.31ghxkeac.3.le.salesforce.com".
You can put this email address as BCC in the script itself.
Are you using "Yet another mail merge", available in the Apps Script Gallery ?
If you open your spreadsheet and click on Tools > Script Editor, you can edit the script.
Search for "bcc" in the script and add the email address you want to use as bcc.
eg: bcc: "emailtosalesforce#n-xvh0q8 2w.31ghxkeac.3.le.salesforce.com"
Take a look at the documentation for more explanations:
https://developers.google.com/apps-script/class_gmailapp#sendEmail
If you're using "Yet another mail merge," perform a search for bcc. Where the code reads "bcc = (e.parameter.addMeAsBCCCheckbox == 'true') ? user : ''" replace "e.parameter.addMeAsBCCCheckbox == 'true') ? user : ''" with the email address you want to bcc to. Make sure you check the "I want to receive a copy of each email sent"
The final code should look like this:
function startStandardMerge_(e) {
var kind = (e.parameter.items == null) ? 'gmail' : 'docs';
var selectedTemplate = GmailApp.getThreadById(e.parameter.chosenTemplate).getMessages()[0];
var user = Session.getEffectiveUser().getEmail();
var bcc = "EMAIL ADDRESS YOU WANT TO BCC TO";
var name = e.parameter.chosenName;
var from = e.parameter.chosenFrom;
merge(kind, selectedTemplate, name, from, bcc);
This feature is built in to "Yet another mail merge". Add a column named "bcc" to your spreadsheet and it will automatically be used in the email's bcc field.
Old version required you to modify script/bcc section in script editor, not case anymore using "Yet another mail merge". Just add column named "bcc" to spreadsheet (as mdahlman advised). Works perfect. Note: did not show email was BCCed in outbox, but it worked (I used unique bcc email for email-to-salesforce, and it logged just fine).