Stay organized with collections
Save and categorize content based on your preferences.
publicstaticclassMailService.Message
Messages are prepared by the caller, and then submitted to the Mail service
for sending. Different fields are subject to different constraints, as
enumerated in the send and sendToAdmins methods.
A collection containing the 'to' field recipients.
setAmpHtmlBody(String ampHtmlBody)
publicvoidsetAmpHtmlBody(StringampHtmlBody)
Sets the AMP HTML body of this message. This field is optional. Setting AMP HTML body makes
the email an AMP Email. Plain text or HTML may become fallback content depending on the email
client used.
Sets the attachments of this message. attachments may be
null, otherwise each attachment must have a corresponding file
name with an extension not on the block list.
Sets the attachments of this message. attachments may be
null, otherwise each attachment must have a corresponding file
name with an extension not on the block list.
Sets the 'bcc' field of this message. Each string represents exactly one
email address. Having null (or invalid addresses) will lead bcc eventual
failure during the send process.
Sets the 'bcc' field of this message. Each string in the collection
represents exactly one email address. Having null (or invalid addresses)
will lead bcc eventual failure during the send process.
A collection containing the email addresses bcc set as the
'bcc' field.
setCc(String[] cc)
publicvoidsetCc(String[]cc)
Sets the 'cc' field of this message. Each string represents exactly one
email address. Having null (or invalid addresses) will lead cc eventual
failure during the send process.
Sets the 'cc' field of this message. Each string in the collection
represents exactly one email address. Having null (or invalid addresses)
will lead cc eventual failure during the send process.
sender must correspond to the valid email address of one of
the admins for this application, or to the email address of the
currently logged-in user. Sender is really the From: field of the email.
A string containing the new text body of this message.
setTo(String[] to)
publicvoidsetTo(String[]to)
Sets the 'to' field of this message. Each string represents exactly one
email address. Having null (or invalid addresses) will lead to eventual
failure during the send process.
Sets the 'to' field of this message. Each string in the collection
represents exactly one email address. Having null (or invalid addresses)
will lead to eventual failure during the send process.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003e\u003ccode\u003eMailService.Message\u003c/code\u003e objects are prepared by the caller and then submitted to the Mail service for sending.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eMessage\u003c/code\u003e class inherits several methods from \u003ccode\u003ejava.lang.Object\u003c/code\u003e, such as \u003ccode\u003eclone()\u003c/code\u003e, \u003ccode\u003eequals()\u003c/code\u003e, and \u003ccode\u003etoString()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can construct a \u003ccode\u003eMessage\u003c/code\u003e using either a default constructor, or a convenience constructor specifying the sender, recipient, subject, and text body.\u003c/p\u003e\n"],["\u003cp\u003eMessages can have several attributes, including attachments, AMP HTML body, HTML body, text body, headers, as well as \u003ccode\u003eto\u003c/code\u003e, \u003ccode\u003ecc\u003c/code\u003e, and \u003ccode\u003ebcc\u003c/code\u003e recipients.\u003c/p\u003e\n"],["\u003cp\u003eMethods are available to set and get the various attributes of a \u003ccode\u003eMessage\u003c/code\u003e object, with certain constraints, such as the sender needing to be a valid admin address, or the subject needing to be not null or empty.\u003c/p\u003e\n"]]],[],null,["# Class MailService.Message (2.0.0)\n\n public static class MailService.Message\n\nMessages are prepared by the caller, and then submitted to the Mail service\nfor sending. Different fields are subject to different constraints, as\nenumerated in the `send` and `sendToAdmins` methods. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e MailService.Message \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nConstructors\n------------\n\n### Message()\n\n public Message()\n\n### Message(String sender, String to, String subject, String textBody)\n\n public Message(String sender, String to, String subject, String textBody)\n\nConvenience constructor for simple messages\n\nMethods\n-------\n\n### getAmpHtmlBody()\n\n public String getAmpHtmlBody()\n\nGets the AMP HTML body of this message. See [#setAmpHtmlBody](/appengine/docs/standard/java-gen2/reference/services/bundled/latest/com.google.appengine.api.mail.MailService.Message#com_google_appengine_api_mail_MailService_Message_setAmpHtmlBody_) for more details.\n\n### getAttachments()\n\n public Collection\u003cMailService.Attachment\u003e getAttachments()\n\nGets the attachments of this message.\n\n### getBcc()\n\n public Collection\u003cString\u003e getBcc()\n\nGets the recipients in the 'bcc' field of this message.\n\n### getCc()\n\n public Collection\u003cString\u003e getCc()\n\nGets the recipients in the 'cc' field of this message.\n\n### getHeaders()\n\n public Collection\u003cMailService.Header\u003e getHeaders()\n\nGets the headers of this message.\n\n### getHtmlBody()\n\n public String getHtmlBody()\n\nGets the html body of this message.\n\n### getReplyTo()\n\n public String getReplyTo()\n\nGets the reply to field of this message.\n\n### getSender()\n\n public String getSender()\n\nGets the sender of this message.\n\n### getSubject()\n\n public String getSubject()\n\nGets the subject of this message.\n\n### getTextBody()\n\n public String getTextBody()\n\nGets the text body of this message.\n\n### getTo()\n\n public Collection\u003cString\u003e getTo()\n\nGets the recipients in the 'to' field of this message.\n\n### setAmpHtmlBody(String ampHtmlBody)\n\n public void setAmpHtmlBody(String ampHtmlBody)\n\nSets the AMP HTML body of this message. This field is optional. Setting AMP HTML body makes\nthe email an AMP Email. Plain text or HTML may become fallback content depending on the email\nclient used.\n\n### setAttachments(MailService.Attachment\\[\\] attachments)\n\n public void setAttachments(MailService.Attachment[] attachments)\n\nSets the attachments of this message. `attachments` may be\n`null`, otherwise each attachment must have a corresponding file\nname with an extension not on the block list.\n\n### setAttachments(Collection\\\u003cMailService.Attachment\\\u003e attachments)\n\n public void setAttachments(Collection\u003cMailService.Attachment\u003e attachments)\n\nSets the attachments of this message. `attachments` may be\n`null`, otherwise each attachment must have a corresponding file\nname with an extension not on the block list.\n\n### setBcc(String\\[\\] bcc)\n\n public void setBcc(String[] bcc)\n\nSets the 'bcc' field of this message. Each string represents exactly one\nemail address. Having null (or invalid addresses) will lead bcc eventual\nfailure during the send process.\n\n### setBcc(Collection\\\u003cString\\\u003e bcc)\n\n public void setBcc(Collection\u003cString\u003e bcc)\n\nSets the 'bcc' field of this message. Each string in the collection\nrepresents exactly one email address. Having null (or invalid addresses)\nwill lead bcc eventual failure during the send process.\n\n### setCc(String\\[\\] cc)\n\n public void setCc(String[] cc)\n\nSets the 'cc' field of this message. Each string represents exactly one\nemail address. Having null (or invalid addresses) will lead cc eventual\nfailure during the send process.\n\n### setCc(Collection\\\u003cString\\\u003e cc)\n\n public void setCc(Collection\u003cString\u003e cc)\n\nSets the 'cc' field of this message. Each string in the collection\nrepresents exactly one email address. Having null (or invalid addresses)\nwill lead cc eventual failure during the send process.\n\n### setHeaders(MailService.Header\\[\\] headers)\n\n public void setHeaders(MailService.Header[] headers)\n\nSets the headers of this message. `headers` may be `null`,\notherwise each header name must be one of the allowed names.\n\n### setHeaders(Collection\\\u003cMailService.Header\\\u003e headers)\n\n public void setHeaders(Collection\u003cMailService.Header\u003e headers)\n\nSets the headers of this message. `headers` may be `null`,\notherwise each header name must be one of the allowed names.\n\n### setHtmlBody(String htmlBody)\n\n public void setHtmlBody(String htmlBody)\n\nSets the html body of this message. At least one of `textBody` and `htmlBody`\nmust not be `null`.\n\n### setReplyTo(String replyTo)\n\n public void setReplyTo(String replyTo)\n\n`replyTo` may be `null`, or must be a valid email\naddress otherwise.\n\n### setSender(String sender)\n\n public void setSender(String sender)\n\n`sender` must correspond to the valid email address of one of\nthe admins for this application, or to the email address of the\ncurrently logged-in user. Sender is really the From: field of the email.\n\n### setSubject(String subject)\n\n public void setSubject(String subject)\n\nSets the subject of this message. A null or empty subject will lead to\neventual failure during the send process.\n\n### setTextBody(String textBody)\n\n public void setTextBody(String textBody)\n\nSets the text body of this message. At least one of `textBody` and\n`htmlBody` must not be `null`.\n\n### setTo(String\\[\\] to)\n\n public void setTo(String[] to)\n\nSets the 'to' field of this message. Each string represents exactly one\nemail address. Having null (or invalid addresses) will lead to eventual\nfailure during the send process.\n\n### setTo(Collection\\\u003cString\\\u003e to)\n\n public void setTo(Collection\u003cString\u003e to)\n\nSets the 'to' field of this message. Each string in the collection\nrepresents exactly one email address. Having null (or invalid addresses)\nwill lead to eventual failure during the send process."]]