所有......这里的新成员...... 我为EDU管理了多个Google Apps域。 Google会发送有关用户活动的各种电子邮件通知,包括可疑的登录活动。这些通知不会发送给用户自己,所以我想自动化其中一些。
通知包含用户名(ID),但不包含实际的电子邮件地址。
我和我的团队开发了一个Google脚本来搜索特定邮件,从邮件正文中提取用户名,然后转发自定义支持邮件和Google发送的邮件。
当我们测试脚本时,我们收到错误: 电子邮件无效:user@mydomain.edu(第30行," myScript") 。
使用通过脚本获取的任何用户名都会产生此错误: var msgTo = userAffected +" @ mydomain.edu";
所有用户帐户都已经过验证,并且处于有效状态。
如果我们对用户电子邮件地址进行硬编码,则脚本可以正常工作。
我已经找到了不可打印的角色,没有发现太多......
有什么想法吗?
我附上了以下代码:
function searchTxt(myTXT) {
//work with labels:
//labelDect and labelProc: labels given to specific messages as they come automatically by the inbox filter/label tool
//the labelDect is removed from the message after it gets processed.
var labelDect = GmailApp.getUserLabelByName("suspicious login detected");
var labelProc = GmailApp.getUserLabelByName("suspicious login processed");
//adminMessage: informational administrative message from domain admin to user.
var adminMessage = 'Google made us aware that your account might have been hacked.<br/><br/>If you have been contacted about this (or a similar) notice recently, or if you think this is an error, please disregard this message; our duty is to assist you with your account security.<br/><br/>If you suspect that your account was indeed, hacked, please change your password.<br/><br/>You can follow the password change instructions directly from Google or you can contact Jackson State University\'s IT support at (601)-979-0838.<br/><br/>Regards.<br/>';
//signature(+=): include html email admin signature.
var signature = '<div><div dir="ltr"><div style="text-align:center"><font face="verdana, sans-serif">_______________________________________________________</font></div>';
signature += '<div style="text-align:center"><font face="verdana, sans-serif"><br></font></div><div style="text-align:center"><font face="verdana, sans-serif"><img src="http://www.somedomain.com"><br>';
//threads: search admin inbox for specific messages.
var threads = GmailApp.search('label:suspicious login detected AND From: "apps-noreply@google.com"');
//Logger: output data to log console/file.
Logger.log( threads.length.toString() );
//forwardOptions: forward message options.
var forwardOptions = {
from:"domain.admin@domain.edu",
subject:"Please, review important information about your e-mail account",
//cc: "domain.admin@domain.edu"
}
//outer loop to deal with google email threads
for ( var currThreadinx = 0; currThreadinx < threads.length; currThreadinx++) {
var messages = threads[currThreadinx].getMessages();
//inner loop to deal with messages inside the threads
for (var msgIndx = 0; msgIndx < messages.length; msgIndx++) {
//email message plain form
var msgBody = messages[msgIndx].getPlainBody();
//substring delimiters to size the substring to capture the usersid
var strIndx = msgBody.indexOf('User: ') + String('User: ').length;
var endIndx = msgBody.indexOf('\n',strIndx);
//actual username
var userAffected = msgBody.substring(strIndx,endIndx);
//appending the domain to the username
var msgTo = userAffected + "@domain.edu";
//append all the parts to send the actual message
forwardOptions.htmlBody = adminMessage + "<br/>" + signature + "<br/><br/>---------- Forwarded message ----------<br/>" + "From: " + messages[msgIndx].getFrom() + "<br/>" + "Date: " + messages[msgIndx].getDate() + "<br/>" + "Subject: " + messages[msgIndx].getSubject() + "<br/><br/>" + messages[msgIndx].getBody();
messages[msgIndx].forward(msgTo,forwardOptions)
// succesfullll test with hardcoded email address
//messages[msgIndx].forward("hard-coded-emailaddress@anotherdomain.com",forwardOptions)
}
//process labels so that old messages don't get reprocessed.
labelProc.addToThread(threads[currThreadinx]);
labelDect.removeFromThread(threads[currThreadinx]);
}
};