Gmail AppScript mailMessage.getFrom() to return email not name

后端 未结 1 640
闹比i
闹比i 2021-01-27 03:20

Similar to: Getting only email address to display when using message.getFrom() in JavaMail but could not apply the solution.

Trying to use mailMessage.getFrom()

1条回答
  •  醉梦人生
    2021-01-27 04:10

    This appears to be a bug!

    It appears that when using the getFrom() method in a card, the name appears but not the email address as you described, which is counter to what is contained in the GmailMessage.getFrom() documentation.

    I have taken the liberty of reporting this behaviour for you on Google's Issue Tracker:

    • GmailMessage.getFrom() not returning email address within CardService.

    You can hit the ☆ next to the issue number in the top left of this page which lets Google know more people are encountering this and so it is more likely to be seen to faster.

    Workaround:

    In the mean time, as the getFrom() method still works within the Apps Script interface, you can obtain the email address from the return string of getFrom().

    If you use Logger.log(mailMessage.getFrom()), you get a return in the log of the form:

    Firstname Lastname 
    

    So, all you need to do is replace:

    var from = mailMessage.getFrom();
    

    with:

    var from = mailMessage.getFrom().split("<")[1].split(">")[0];
    

    I hope this is helpful to you!

    References:

    • Google Apps Script - GmailMessage.getFrom()
    • Issue Tracker - GmailMessage.getFrom() not returning email address within CardService.

    0 讨论(0)
提交回复
热议问题