I am trying to automate sending emails on Google sheets using Mailapp.
My problem is the following:
I need to include the gmail signature in the email.
When using Mailapp, the pre-defined signature on gmail does not appear.
Is there any solution for that?
The other solution, as I found online, is using HTML.
I need to develop the email automation for many users on a single google sheet and need to include Linkedin links.
My issue here is that I am not able to assign HTML's 'href' as a variable (variable that is in fact a cell containing the linkedin link.
JS:
var linkedin_link = SpreadsheetApp.getActiveSheet().getRange(1, 1).getValue();
var templ = HtmlService.createTemplateFromFile("MailTemplate");
var message = templ.evaluate().getContent();
MailApp.sendEmail({
to: "xxx#gmail.com",
subject: "Automation",
htmlBody: message,
});
HTML file:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<a href="https://linkedin.com/" + linkedin_link >LINKEDIN</a>
</body>
</html>
If anyone could help it would be great!
Thanks!
If you enable Gmail advance API (under services) you can use this to get the signature as HTML. Then you can use this in your own html template:
function readCurrentOutOfOffice(){
console.log(Gmail.Users.Settings.getVacation('user#company.com'))
}
Related
I create function get gmail when user use my app in file gs. When i call function via file script html it run but don't get gmail ?
I try test open new web browsers, log in with account gmail and pass URL of apps script but not show my gmail.
Code in file .gs:
function checkAccSS(){
var email = Session.getActiveUser().getEmail();
Logger.log(email); // I test it show my gmail
return email;
}
Code in file .html:
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="doLoadGmail()">
<p id="demo"></p>
<script>
function doLoadGmail(){
google.script.run.withSuccessHandler(checkGmall).checkAccSS();
}
function checkGmall(email){
document.getElementById("demo").innerHTML = "Gmail " + email;// not show gmail in html !
console.log(info); // not show gmail here !
}
</script>
</body>
</html>
As far as I can see this happens because your script 'doLoadGmail()' that executes the script 'checkAccSS' is only called on load. You could add a button with an onclick event that would execute your script without reloading however this wouldn't do it automaticly.
If you would like to this automaticly you could check the documentation from Ajax
https://www.w3schools.com/jquery/jquery_ref_ajax.asp
I have created one portal where I want to configure outlook with the portal. There will be Email button where on click outlook should get open where subject, body and attachment should be added automatically based on data in the database.
I can open outlook and set subject and body but don't know how to add an attachment.
I have checked this link Javascript: Outlook but I am getting ActiveX exception but I believe this is more compatible with IE. Also , Microsoft - Outlook
<html>
<head>
<script>
function myFunction() {
window.location.href = "mailto:test#test.com?subject=TestSubject&body=message%20goes%20here";
}
</script>
</head>
<body>
<button onclick="myFunction()">Open Outlook</button>
</body>
</html>
According to your description, you want to add an attachment with JS, you can use the following code:
mailItem.Attachments.Add("your prfile url");
You need to set “Initializing and scripting ActiveX controls that are not marked as secure” to enabled.
In IE
This is the result of my running:
This question already has answers here:
Is JavaScript supported in an email message?
(11 answers)
Closed 5 years ago.
Can you use JavaScript inside an email, which is sent using Python?
My aim is to send a working clock inside an email.
I am trying to use Python to do so. I am using IDLE and the Python libraries stmplib, email and html2text to send emails. My code looks like the code shown below. I omitted some details (style and script) as they are unimportant.
me = "my.email#gmail.com"
you = "my.email#gmail.com"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Clock"
msg['From'] = me
msg['To'] = you
html = """\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clock</title>
<style></style>
</head>
<body>
<div class="clock">
<p class="clockhour">HH</p>
<p class="clocksym1">:</p>
<p class="clockminute">MM</p>
<p class="clocksym2">:</p>
<p class="clocksecond">SS</p>
</div>
<script type="text/javascript"></script>
</body>
</html>
"""
text = html2text(html)
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = SMTP('smtp.gmail.com:587')
s.ehlo()
s.starttls()
s.login("my.email#gmail.com", "my password")
s.sendmail(me, you, msg.as_string())
s.quit()
The full version of the HTML in this code gives me a properly functioning clock, but if I attempt sending it to myself using Gmail I receive a different result.
Viewing the HTML:
In Gmail:
This shows, that parts of the CSS load, but others like the font or the font size don't. It also shows that the JavaScript does not load. (Normally viewing the HTML code in a browser gives a functioning clock, while in an email doesn't.)
Is there a way to send an email with this clock?
Short Answer: No. You can't use JavaScript for email template.
Tricky way: You can work on relevant file and get the parsed value in your template file using server side language.
Example:
clock.js
// code for js
template.php
// echo the value
// The value is rendered in html and works in email template too.
But this case is not suitable for you as you're trying to implement countdown clock. This is suitable only for static value.
However, linking to external page content will help you to show the timer.
For your case, You may try using http://motionmailapp.com/
Hope, this helps!
javascript is unsupported in email html, but at least you can place a link to the page with clock countdown.
Good morning and thank you in advance for the help. I am a noobi at java/gas scripting so any help is appreciated.
On a google spreadsheet I have a custom menu that launches a small html menu that I would like to be able to launch various web pages from. The actual addresses are variable. I have set those as Keys with the property service when the page launches.
Here is the html code (taken from another example and trying to adapt)"
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<script type="text/javascript">
var myArr = ["Peter", "Paul", "Tony", "Adam"];
function display(name) {
var accScriptPageLinkID= PropertiesService.getScriptProperties().getProperty('scriptPageLinkAdd');
Logger.log(accScriptPageLinkID)
alert(name);
}
for(var i = 0; i < 4; i ++) {
document.write('<input type="button" onclick="display(this)" name="'+ myArr[i] + '" value="'+ myArr[i] +'">'); // Will log Peter, Paul..
}
</script>
</body>
</html>
I need to modify the above code so that when the button Peter is pressed it opens the Script Page linked under the Property Service Key 'scriptPageLinkAdd'.
Or if there is an easier way to create a dynamic html page for my menu that is linked to cells in the google spreadsheet, please advise.
Mike
PropertiesService (and Logger too) are server-side AppsScript classes - they can't be invoked directly from the client side (your html page).
To invoke them on the server side from your html page you must use google.script.run.withSuccessHandler(clientSideFunctionToProcessReturnedData).someServerSideFunction() which can return some data back to your html page.
Learn more about HtmlService and communicating with the server here
I have a bit of embed code that I need to place on a Google Site, this site will be restricted to our Google domain members. I can place this JavaScript in a Google Gadget and it works fine.
<script type="text/javascript" src='https://HOSTNAME/Forms/js/forms-embed.js?v=9.2'>
</script>
<script type="text/javascript">
var lfembed = new LaserficheForms.Form(null /*element to place form in*/,{bpid: '1', host:'https://HOSTNAME/Forms', params:PARAMS, autoheight: false}).getFrm();
lfembed.style.height = "100%";
</script>
The problem is that I want to be able to get the currently logged in user's email address and pass that in the params: section of the code above.
From what I can tell, you can't do this within a Google Gadget. I can retrieve the current email address with the Google Apps Script object below, but I don't know how to make the two work together.
function doGet() {
var gauser = Session.getActiveUser().getEmail();
var output = ContentService.createTextOutput(gauser);
return output;
}
Another problem is that Google sanitizes some of the JavaScript when I try to include all of the code in just the Google Apps Script.
I really don't have much experience in this area, so if anyone could point me in the right direction I'd appreciate it.
I learned about JSONP today.
I ended up getting this to work by publishing the following Google Apps Script web app.
function doGet(request) {
var gauser = Session.getActiveUser().getEmail();
return ContentService.createTextOutput(
request.parameters.prefix + '(' + JSON.stringify(gauser) + ')')
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
Then I called the web app service via URL in my XML Gadget
<script src="https://WEBAPPURL?prefix=lfdo"></script>
This placed the username value into the lfdo function, which I inserted into the parameter string I needed it in.
The full Content section of the XML gadget:
<![CDATA[
<script type="text/javascript" src='https://HOSTNAME/Forms/js/forms-embed.js?v=9.2'></script>
<script type="text/javascript">
function lfdo(gauser) {
console.log(gauser);
var lfembed = new LaserficheForms.Form(null /*element to place form in*/,{bpid: '1', host:'https://HOSTNAME/Forms', params:'Name='+ gauser, autoheight: false}).getFrm();
lfembed.style.height = "100%";
gadgets.window.adjustHeight();
}
</script>
<script src="https://WEBAPPURL?prefix=lfdo"></script>
]]>
This article on Google Developers set me in the right direction.