I have a Google Sheet, its have several internal code (gs) and finish doing a list with mails and text, actually Im using a function to send mails:
function SendMail () {
var vAuxiliar = SpreadsheetApp.getActive().getSheetByName("Auxiliar");
var vLast = vAuxiliar.getDataRange().getNumRows();
var vDataRange = vAuxiliar.getRange("A2:E"+vLast);
var vValues = vDataRange.getValues();
for(var i in vValues) {
var vemailAddress = vValues[i][1];
var vMensaje = vValues[i][4];
var vSubject = 'Contact.';
MailApp.sendEmail(vemailAddress, vSubject, vMensaje);
};
};
Its works great but mails are incoming with my personal account, I need change this function to send mails with my enterprise account, we use MS Outlook, it is possible?
Thanks in advance!!!
You sure cannot use the Gmail service to send messages through your MS Outlook account.
But a possible workaround would be to create aliases for your MS Outlook account in your Gmail account, and then using this alias when sending.
GmailApp.sendEmail(to, 'Subject', 'A message sent from an alias!', {'from': "enterprise#example.com"});
But for using this from parameter in sendEmail you need to be able to retrieve it as an alias with getAliases().
Refer to this page to add your enterprise mail as an aliases to be able to use later.
Note that using the term alias here refers to the Gmail terminology as external email address. Do not check "Treat as alias" when configuring your MS Outlook account. This is another story.
Also as Ruben said in the comments you could try to ask if there are any API you can use to send mail. In that case you should try to use the URL fetch method.
Related
I have created a number of tools that use Installable Triggers to send emails. Because I'm the one who wrote the scripts, and created the triggers, those emails are all sent from my account.
I am wondering if there is a way to create those installable triggers, not as my own account, but as a Google Group account. Ideally, I would like for those triggered emails to be sent from the Group's account, as opposed to my own. I am an Owner of the Google Group that I would like to use, so if it's possible, I should have the appropriate security. I'm just not sure if there's a way to log in as the Group, so that I can create the triggers from the Group's account, and therefore have the emails sent from the Group's account. Is that possible?
You don't need to sign in your group in the script, you just need to add the group email to your gmail settings Send mail as:
After adding it, a window will prompt you and add your group credentials there. After confirmation, you should be able to use that email as your parameter for sendEmail. See code below.
Code:
function sendEmailUsingGroupEmail() {
var alias = GmailApp.getAliases();
var groupEmail = "group#domain.com";
var toEmail = "test#domain.com";
var strSubject = "subject";
var strContent = "this is content";
// Check first if that email exists after adding
if(alias.includes(groupEmail))
GmailApp.sendEmail(toEmail,strSubject,strContent,{from: groupEmail});
}
I have the following code
var mailOptions = {};
mailOptions.attachments = attachmentArray;
mailOptions.htmlBody = htmlbody;
var alias = ??? // I have no idea what to put here. I've tried just putting in a string with the address
mailOptions.from = alias;
if(email){
GmailApp.sendEmail(email, subject,"",mailOptions);
I'm trying to send an email using an alias but I have multiple aliases to choose from. I saw somewhere that I can maybe use this
Gmail.Users.Settings.SendAs.Get
I should mention that while I wrote the script, I am not the owner of the spreadsheet. The original owner has a G Suite account, and wants to use their alias above. So it is not my alias, but they will be the one running the script.
First you should add an alias to Gmail. You can do this from the Gmail web app (see Send emails from a different address or alias) Also you might do this by using the Gmail API (see Managing Aliases
Once your Gmail account has one or more alias, you can use send email from an alias by adding its email address to the corresponing property of the GmailApp.sendEmail options argument.
Related
Email via Google Apps Script from another email address
It it possible to change the from address when using sendEmail?
I've got a working Sheets / Google Code script to pull information from a sheet and fire it into a HTML templated e-mail but was wondering if there's any way you can define the senders address beyond the user you're authenticated to.
i.e. User is authenticated into G-Suite and has access to shared mailboxes. Is there a way of defining which mailbox to send from via Google Apps Script?
Couldn't see any documentation on this so hold limited hopes but wanted to check with the community at SO before closing it off.
Google documentation: https://developers.google.com/apps-script/reference/mail/mail-app
Thanks
Using GmailApp instead, you can select one of your available aliases using sendEmail(recipient, subject, body, options).
For example:
GmailApp.sendEmail("recipient#example.com", "Subject", "Body", {from: "alias#example.com"});
Note that to do so, the from address must be an available alias. You can check available aliases with this function:
function listAliases() {
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
}
I'm trying to update users of my domain to a new adress ,basically the same command than gam which is : " gam update user userx username mailadress#x.com "
My goal is to make the same thing but using google apps script, the documentation isn't very helpful because "AdminDirectory.Users.update(resource, userKey)" is even not present in it.
function updateUserName() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
var mailAdress= sheet.getRange(1, 1).getValue();
var user = AdminDirectory.Users.get(colAdresseMail);
user.emails = [address='newtest#mydomainname.com', primary=true];
Logger.log(user);
}
When I'm looking at logs, the address is now the new adress I want, but when I'm sending a mail to this adress, I have 2 mails , one with the mail I needed to have, and another mail delivery subsystem..
Maybe I forgot something?
In the web UI, the alias is added automatically when you change an email address. Based on my previous work with this and the results you're seeing, I believe GAM does it programmatically (GETs original address and inserts it as an alias during the change) if you're seeing that behavior. You could check this in the source for GAM here if you'd like to be 100% sure.
You will need to use something like the following insert to set the alias like you've updated the email address in your comment:
AdminDirectory.Users.Aliases.insert(alias, email)
The documentation on this can be found here within the Directory API section of the Google Developers site.
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.