如何在Google App Script生成的电子邮件中显示数据URI图像?
var recipient = Session.getActiveUser().getEmail();
var subject = 'SP500 chart';
var page = UrlFetchApp.fetch('http://www.barchart.com/chart.php?sym=%24SPX&style=technical&template=&p=MO&d=M&sd=&ed=&size=M&log=0&t=CANDLE&v=0&g=1&evnt=1&late=1&o1=&o2=&o3=&sh=100&indicators=&addindicator=&submitted=1&fpage=&txtDate=#jump').getContentText();
var tag_begin = page.indexOf('data:image');
var tag_end = page.indexOf('>', tag_begin);
var content = page.substring(tag_begin, tag_end);
MailApp.sendEmail(recipient, subject, '', {'htmlBody': content});
答案 0 :(得分:0)
不知何故,Apps脚本编译器无法识别string.indexOf()方法。
修改代码以检索所需的值。
function testurl(){
var page = UrlFetchApp.fetch('http://www.barchart.com/chart.php?sym=%24SPX&style=technical&template=&p=MO&d=M&sd=&ed=&size=M&log=0&t=CANDLE&v=0&g=1&evnt=1&late=1&o1=&o2=&o3=&sh=100&indicators=&addindicator=&submitted=1&fpage=&txtDate=#jump').getContentText();
var tag_begin = page.search('data:image');
var searchString = page.substring(tag_begin);
var tag_end = searchString.search('/>');
var tag_endpage = tag_begin + tag_end;
var content = page.substring(tag_begin, tag_endpage);
}
希望有所帮助!