添加电子邮件签名到电子邮件通知脚本 [英] Add Email Signature to Email Notification Script

查看:214
本文介绍了添加电子邮件签名到电子邮件通知脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我每次在网站上发布新通知时,都会在Google Apps脚本上编写代码发送电子邮件。以下是供参考的代码:

  var url_of_announcements_page =https://sites.google。 COM /公告; 
var who_to_email =emailaccount;

函数emailAnnouncements(){
var page = SitesApp.getPageByUrl(url_of_announcements_page);
if(page.getPageType()== SitesApp.PageType.ANNOUNCEMENTS_PAGE){

var announcements = page.getAnnouncements({start:0,
max:10,
includeDrafts:false,
includeDeleted:false});
announcements.reverse();
for(var i in announcements){
var ann = announcements [i];
var updated = ann.getLastUpdated()。getTime();
if(updated> PropertiesService.getScriptProperties()。getProperty(last-update)){
var options = {};

options.htmlBody = Utilities.formatString(< h1>< a href ='%s'>%s< / a>< / h1>%s,ann.getUrl (),ann.getTitle(),ann.getHtmlContent());

MailApp.sendEmail(who_to_email,Announcement - '+ ann.getTitle()+',ann.getTextContent()+\\\
\\\
+ ann.getUrl() ,选项);

PropertiesService.getScriptProperties()。setProperty('last-update',updated);




$ b函数设置(){
PropertiesService.getScriptProperties()。setProperty('last-update' ,new Date()。getTime());
}

我想知道是否可以将我的gmail签名添加到码。当我用脚本发送它时,我的签名被删除。我是否必须在代码中签名,或者我能否从gmail获得我的签名并在最后自动插入?这里是电子邮件格式化的一行:

  MailApp.sendEmail(who_to_email,Announcement - '+ ann.getTitle()+',ann.getTextContent()+\\\
\\\
+ ann.getUrl(),options);


解决方案

Apps脚本无法访问用户的签名:没有方法在MailApp中,或 GmailApp ,甚至在< Gmail API 可以通过高级Google服务访问。原则上,您可以使用GmailApp获取最近传出的消息,并搜索其文本以查找最后一个 - 。但是这需要给脚本更多的访问权限(与MailApp不同,GmailApp可以访问,转发和删除现有的电子邮件),并且容易出错(文本解析失败时,最终会在邮件中出现令人尴尬的文本片断)。



直接追加:

  var signature =\ n \ n  -  \\\
FirstName LastName;
// ...
MailApp.sendEmail(... + signature,options);

(顺便说一句,Gmail网页界面和Gmail移动应用程序一般都有不同的用户签名,另一个脚本生成的消息似乎并不罕见。)


I am writing a code on Google Apps Script to send an email every time there is a new announcement made in my site. Here is the code for reference:

var url_of_announcements_page = "https://sites.google.com/announcements"; 
var who_to_email = "emailaccount";

function emailAnnouncements(){
  var page = SitesApp.getPageByUrl(url_of_announcements_page); 
  if(page.getPageType() == SitesApp.PageType.ANNOUNCEMENTS_PAGE){ 

    var announcements = page.getAnnouncements({ start: 0,
                                               max: 10,
                                               includeDrafts: false,
                                               includeDeleted: false});
    announcements.reverse();                                    
    for(var i in announcements) { 
      var ann = announcements[i]; 
      var updated = ann.getLastUpdated().getTime(); 
      if (updated > PropertiesService.getScriptProperties().getProperty("last-update")){ 
        var options = {}; 

        options.htmlBody = Utilities.formatString("<h1><a href='%s'>%s</a></h1>%s", ann.getUrl(), ann.getTitle(), ann.getHtmlContent());

        MailApp.sendEmail(who_to_email, "Announcement - '"+ann.getTitle()+"'", ann.getTextContent()+"\n\n"+ann.getUrl(), options);

        PropertiesService.getScriptProperties().setProperty('last-update',updated);
      }
    }
  }
}

function setup(){
 PropertiesService.getScriptProperties().setProperty('last-update',new Date().getTime());
}  

I would like to know if it is possible to add my gmail signature to the code. As when I send it with the script my signature is removed. Do I have to make my signature in the code or am i able to get my signature from gmail and automatically insert it at the end? Here is the line for the formatting of the email:

MailApp.sendEmail(who_to_email, "Announcement - '"+ann.getTitle()+"'", ann.getTextContent()+"\n\n"+ann.getUrl(), options);

解决方案

Apps Script cannot access user's signature: there is no method for that in MailApp, or GmailApp, or even in Gmail API accessible via Advanced Google Services.

In principle, you could use GmailApp to get a recent outgoing message and search its text for the signature contained after the last -- found in message body. But this requires giving the script a lot more access (GmailApp can access, forward and delete existing email, unlike MailApp) and is error-prone (when text parsing fails, you might end up with an embarrassing fragment of text in your message).

Just append it directly:

var signature = "\n\n--\nFirstName LastName"; 
// ... 
MailApp.sendEmail(... +signature, options);

(By the way, Gmail web interface and Gmail mobile app have different user signatures in general, so having another one for script-generated messages doesn't seem unusual.)

这篇关于添加电子邮件签名到电子邮件通知脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆