且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法从Google应用程序脚本中的Gmail邮件对象中获取特定的电子邮件地址?

更新时间:2023-09-07 15:02:10

getFrom() method should return the sender of the message in the format Some Person <someone@somewhere.com>. If you need just the email address portion of the string, you can extract it using regular expression like this (adapted example from getFrom() method description):

var thread = GmailApp.getInboxThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getFrom().replace(/^.+<([^>]+)>$/, "$1"));

That regex replace the string returned by getFrom() method with the part of the string in angle brackets (the sender's email address).

相关阅读

推荐文章