Insert text with hyperlink in Gmail with Google Script?

Inserting a hyperlink in email requires sending the email in HTML, rather than in plain text as you do now. Change the syntax of sendEmail call to sendEmail(Object) where the argument is an object with htmlBody field containing your message. Like this:

var message = {
  to: "[email protected]",
  subject: "Weekly Agenda | " + dateRange,
  htmlBody: "Hi Everyone-\n Here's the <a href='" + agendaURL + ''">agenda</a> for tomorrow's meeting.\n See you in the morning!\n-John Doe", 
  name: "Automatic Emailer Script",
  attachments: [file2.getAs(MimeType.PDF)]
};
MailApp.sendEmail(message); 

Using double quotes for message body is preferable, because then you don't need to escape apostrophes in text.


I have found that sending out emails using GAS is suggested to do so in HTML. zaq just posted his answer right after I found a better way to re-write my code. Thank you zaq though! Here is my working code:

    var emailTo = '[email protected]';
    var subject = "Weekly Agenda | " +dateRange;
    var options = {}
    options.htmlBody = "Hi Everyone-" +'<br />'+'<br />'+ "Here\'s the " + '<a href=\"' +agendaURL+ '">agenda</a>' + " for tomorrow\
's meeting." +'<br />'+'<br />'+ "See you in the morning!" +'<br />'+'<br />'+ "-John Doe";
    options.attachment = [file];
    MailApp.sendEmail(emailTo, subject, '', options);