Is there a way to retrieve the signature of my Gmail account using Google Apps script?
I'm currently using Google Apps Script to send out emails and it would be nice to be able to append my email signature to the end of the email body because Google Apps Script doesn't automatically do so.
While the Gmail API doesn't expose the signature, you can use a workaroud to grab the signature from Gmail.
Create a new Gmail draft, put the word "signature" in the subject and save the draft.
The body will include the signature by default. Do not modify the body.
Save and Close the draft.
Go to Google Script editor and use this script to grab the signature.
function getGmailSignature() {
var draft = GmailApp.search("subject:signature label:draft", 0, 1);
return draft[0].getMessages()[0].getBody();
}
Unfortunately, We don't have any user level access to retrieve our signature but, We have workaround, you can append signature simply copy your signature as a HTML [ Browser inspect mode] code from Gmail UI add to script variable, You can append this HTML string at the end of every email.
You can make it dynamic like name and Email ID
Sample code
function myFunction() {
var signHTML =
'<br><br><br><br><table style="border-bottom:1px solid"><tbody><tr><td><table><tbody><tr><td><table style="padding-right:20px">'+
'<tbody><tr><td></td></tr></tbody></table></td><td><table><tbody><tr><td><font face="open sans, sans-serif">'+
'<span style="font-size: 12px;"><b>YOUR NAME</b></span></font></td></tr><tr><td><font face="open sans, sans-serif">'+
'<span style="font-size: 12px;"><b>DESIGNATION </b></span></font>'+
'</td></tr><tr><td><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-711-XXXX</span>'+
'</div><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-8XXX09-XXXX</span></div>'+
'<div><a href="https://www.searce.com" style="text-decoration:blink;vertical-align:top" target="_blank">'+
'<span style="color:#000000;font-family:open sans,sans-serif;font-size:12px">www.yourComany.com</span></a>'+
'</div></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td></td></tr></tbody></table>';
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: "Upend signature at the end of mail",
htmlBody: "Dear User</b>Signature testing" +
signHTML,
});
}
It works we are using this. Hope it helps you. :)
Related
I want the script to send the created html email template email.html to the person who last submitted the form.
Below is the success message I get in the console:
Below is the actual email that is received by the person who submits the form:
The email.html is formatted correctly and appears perfectly when sent manually.
I hope this is reprex enough.
EDIT: Maybe it's easier if I include the code
function sendEmail () {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var data = ss.getRange(lr,3);
var email = data.getValue();
var message = HtmlService.createTemplateFromFile('email');
var subject = "Test Subject"
GmailApp.sendEmail(email,subject, message);
}
It's not clear why you are using HtmlService.createTemplateFromFile, but from the image it's clear there at least one error, the script misses two methods:
HtmlService.HtmlTemplate.evaluate() to evaluate the Templated HTML
HtmlService.HtmlOutput.getContent() to get the HTML from the HtmlService.HtmlOutput object returned by the previous method.
Another option that looks to be an error is the use of GmailApp.sendEmail(string,string,string) method, as the third parameter should be a string to be used as the email plain text content. If you want to pass HTML, instead use GmailApp.sendEmail(string,string,string, Object)
Related
Emailing Google Sheet range (with or without formatting) as a HTML table in a Gmail message
Sending an email in HTML and plain with a Gmail Apps Script
Google script inject html into html email
References
https://developers.google.com/apps-script/guides/html
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)
Context
We are currently working on a short Apps script that sends links to Google Drive files (shared with anyone with the link) through the MailApp.sendEmail(options) function.
The script works well on our test G Suite domain but on the production domain, it just does not send the emails. There are no error messages.
Some code
The issue can be reproduced through the following pieces of code:
Code.gs file
function test_sendEmail() {
const template = HtmlService.createTemplateFromFile('template.html');
template.link = "https://drive.google.com";
template.title = "This is a link";
const mailBody = template.evaluate().getContent();
console.log("Quota: " + MailApp.getRemainingDailyQuota()); /* Quota is not exceeded. */
try {
const options = {
to: "myEmail#Address.com", /* Replace this with your email address */
subject: "LINK",
htmlBody: mailBody,
noReply: true
};
MailApp.sendEmail(options);
} catch(e) {
console.log(e.message);
}
}
template.html file
Link: <a href='<?= link ?>'><?= title ?></a>
What we tried
Emails are properly sent when the link does not contain the drive.google.com part. For example, emails with links to google.com are sent properly.
We are able to send an email from the Gmail account the script is executed as and this email is sent properly with the Drive links.
As opposite as this question, I do not get "Message blocked" email and using GmailApp.sendEmail instead of MailApp.sendEmail does not seem to change anything.
Finally, the script above works well in the test G Suite domains and in some others we tried.
Thus, I believe that it comes from the G Suite domain configuration that have specific restrictions on Apps script. Is it possible? Where can I change it in the G Suite admin console? What other points should I check to make it work?
More details on the issue:
The script fail to send email both with G Suite, gmail and other
email addresses.
We tried in both Apps script runtime (V8 and legacy). Both doesn't
work properly.
I believe that SPF/DKIM/DMARC are not setup in the domain.
We use the same test recipients in both G Suite environments.
The code after the sendEmail method call is executed properly.
The provided template was just an example to reproduce the issue.
The real template looks like a typical email, with a list of links. It is not link-only.
In the future, the script is supposed to send less than 100 emails per day. Right now, it is just sending a few test emails (not more than in test environment).
We use the default cloud project associated with the script.
The script is bound to a Google Sheets file.
Below is the real template that we use.
Dear Customers,<br/><br/>
We inform you that new documents are available. Please find them below:
<ul>
<? for(let i = 0; i < docs.length; i++) { ?>
<li>Document <a href='<?= docs[i].link ?>'><?= docs[i].title ?></a>, <i><?= docs[i].documentType ?></i> is available</li>
<? } ?>
</ul>
<br/>
Regards,<br/>
Your customer service.
Instead of MailApp use GmailApp (you might have to change the sendEmail parameters, check the docs)
The above because others have being reported similar problems, actually something similar happened recently to me while working on client's project.
Related
MailApp.sendEmail method doesn't get through to accounts with URL in the body - Message Blocked
I'm sending emails using: https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail
I have not been able to find out HOW I can add the Unsubscribe equivalent. This is documented in here: https://sendgrid.com/docs/Classroom/Basics/Marketing_Campaigns/unsubscribe_groups.html#-Using-a-Custom-Unsubscribe-Link
On the website, you just use a shortcode [Unsubscribe], this does not work when sending emails via the sendgrid/mail package.
One tip that would have saved me an hour or two is that:
It's possible to send the following in the api json along with other stuff:
"asm":{
"group_id":123,
"groups_to_display": [123],
}
then the following variables become available to use within the template:
<%asm_group_unsubscribe_raw_url%>
<%asm_preferences_raw_url%>
If you want to keep things simple don't include the following variable as it fiddles with too many things (this wasn't obvious from the documentation so obviously I did so and wasted time :( ):
"tracking_settings": {
"subscription_tracking": {
"enable": true,
"substitution_tag": "[unsubscribe_url]"
}
}
Just use them in their raw format and you shall be fine.
Since you're sending using code, it's a "transactional" type of message. You'll want to either turn on the Subscription Tracking filter at the account level (via [UI](subscription tracking setting) or API), or turn it on as you send the message, as part of the mail/send API call, under tracking_settings.
It's important to note that you can't mix those. If you define anything in the mail/send API call, you'll need to define everything for Subscription Tracking in that call. SendGrid won't look at some settings at the mail level, and some at the account level.
Most users will just set it at the account level. There, you can customize the HTML & Text of the Unsubscribe footer, customize the HTML of the landing page, or redirect landing to a URL of your choosing, which will send the recipient there with ?email=test#domain.com in the URL string for your system to catch. You can also define the "replacement tag" like [%unsubscribe%], so that you can place the URL wherever you want within your HTML.
https://app.sendgrid.com/ > Suppressions > Unsubscribe Groups > Create New Group
Note down group_id/ids. e.g 123 (Only number !Not string)
Send email using node.js
const sgMail = require('#sendgrid/mail');
sgMail.setApiKey(SENDGRID_API_KEY);
const tags = { invitedBy : Alex }
const msg = {
to: email,
from: { "email": SENDER_EMAIL,
"name": SENDER_NAME
},
templateId: TEMPLATE_ID,
dynamic_template_data: {
Sender_Name: name,
...tags
},
asm: {
group_id: 123,
groups_to_display: [
123
],
},
};
await sgMail.send(msg);
The best approach is to use Group Unsubscribes.
First create a group in Sendgrid:
Groups > Unsubscribe Groups > Create a group
Next, insert a module into the Sendgrid template that creates specific tags in your email, which are populated when you make an API request
Go to your template
Insert an unsubscribe module in an HTML block
Save
Finally make an API request and specify the group created in step 1:
"asm":{
"group_id":544,
"groups_to_display": [544, 788],
}
These will be inserted into the module mentioned in step 2 when the email is sent.
Unfortunately Sendgrid unsubscribe links are not as straightforward as they could be. They are explained in more detail here
The easiest way is to do this via the SendGrid GUI.
Go to Settings -> Tracking -> Subscription Tracking
Currently I use NopCommerce 3.60 and use FB External Login.
Problem:
After I login in Nop by FB External Button and it returns to URL mydomain.com/login#_=__ with red message (Email is required) and it does not login user in.
Screenshot: http://postimg.org/image/wvgu6wvud/
What I was try:
Reinstall Nop from scratch and has below setting
In advance setting and option I has:
Externalauthenticationsettings.requireemailvalidation False
Auto register enabled: Checked.
Registration method: Email Validation
I try to debug source code in file name FacebookProviderAuthorizer.cs in Nop.Plugin.ExternalAuth.Facebook folder and also does not get email value too.http://postimg.org/image/qwmphn9tn/
Have anyone suggest me what to do next for this problem please.
Fixed. You can see changeset 5bb6815e30ee
I am not familiar with Nop, but it is possible to register at Facebook without an email. This is why most libraries for fb-oauth checking against eMail and if there is no email, they create an user-id#facebook.com eMail address.
Maybe your Nop library of fb-oauth is out dated?
So please check if there is such a function - if not, you might got your problem.
Somehow FB doesn't include email in oauth. You can use this method to get email and supply that email to register.
//as part of the uri for the webrequest, include all the fields you want to use
var request = WebRequest.Create("https://graph.facebook.com/me?fields=email,name&access_token=" + Uri.EscapeDataString(authorization.AccessToken));
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
System.IO.StreamReader streamReader = new System.IO.StreamReader(responseStream, true);
string MyStr = streamReader.ReadToEnd();
JObject userInfo = JObject.Parse(MyStr);
//now you can access elements via:
// (string)userInfo["name"], userInfo["email"], userInfo["id"], etc.
}
}
in grails-mail plugin you need do define your inline image data in your service, assuming you are using grails mail from a service.
you do this like so in your service.groovy
inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')
inside your service definition, lets say:
def mailService
def contactUser(userName, email) {
mailService.sendMail {
multipart true
to email
from "marc.heidemann#live.de"
subject "Hello from grails-mail"
text "Hallo from grails-mail multipart text modus"
html view:"/alert/test", model:[name:userName]
inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png')
inline 'footer', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif')
}
}
for now, the app is rendering the footer and the header image, Ok.
alright, now the plan of the planners of this project is to render profile pictures from database (about 15.000 users) in their emails - can and if then how can this be achieved without declaring every user's profile picture inside the service.groovy? Furthermore those pictures are stored outside of my app at amazon s3. might this be a boundary of mail plugin or is it possible to get this working? What would you offer those planning and creative guys as an alternative if it is not possible to do so? any opinions are welcome.
Loop through your users.
Get the corresponding picture from S3 using the grails-aws-plugin.
Insert picture into email
Send mail using the mail-plugin
That way you don't have to declare it in the service. You can download the pictures from S3 to use them as inline pictures or you could use a url provided by S3.
To access the file for inline usage:
def file = aws.s3().on(bucket).get(name, path)
To get a public url:
def url = aws.s3().on(bucket).url(name, path)