# Sample Email Messages

The following samples show what types of messages can be sent using the Email control.

### Example 1: HTML Body, No Attachments

If the supplied String body is an HTML document, you can set the content-type annotation attribute to generate the following e-mail.

    To: user@myorg.com
    Subject: Thanks for your order
    Content-Type: text/html

    <html>
    <head>
    <title>Thanks for your order</title>
    ...

### Example 2: Body with Attachments

For a message body with attachments, the Email Control generates a multipart/mixed message with the message body as the first part. Attachments are added as MIME parts with content types in accordance with their file name suffix. The following table lists commonly used file suffixes.

Suffix | Content-Type
--- | ---
.doc | application/msword
.gif | image/gif
.html | text/html
.jar | application/java-archive
.jpg | image/jpeg
.pdf | application/pdf
.txt | text/plain
.xls | application/msexcel
.xml | application/xml or text/xml
.zip | application/x-zip-compressed

Attachments with unknown extensions receive the application/octet-stream MIME type. The Email control also base64 encodes attachments which include binary data, as shown in the following example:

    To: user@myorg.com
    Subject: Thanks for your order
    Content-Type: multipart/mixed;
    boundary="------------F141E40DDE2763DF92513DD4"

    ------------F141E40DDE2763DF92513DD4
    Content-type: text/plain; charset=us-ascii

    Dear Sir,

    Please see the attached diagram and brochure.

    Thanks,
    Customer Service

    ------------F141E40DDE2763DF92513DD4
    Content-type: image/jpeg;
            name="picture.jpg"
    Content-Disposition: attachment; filename="picture.jpg"
    Content-transfer-encoding: base64

    /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlA
    ...

    ------------F141E40DDE2763DF92513DD4
    Content-Type: application/pdf;
            name="brochure.pdf"
    Content-Transfer-Encoding: base64
    Content-Disposition: inline;
            filename="brochure.pdf"

    JVBERi0xLjIgDSXi48/TDQogDTEwIDAgb2JqDTw8DS9MZW5ndGggMTEgMCBSDS9Ga
    ...

    ------------F141E40DDE2763DF92513DD4

### Example 3: No Body, One Attachment

An Email control send action with no body and one attachment does not generate an multipart/mixed message. This supports interchange scenarios that require the XML document to be in the message body.

    To: inbox@myorg.com
    Subject: new XML order
    Content-Type: application/xml

    <?xml version="1.0" ?>
    <PurchaseOrder>
    ...

### Exceptions and Errors

You can use an exception handler to catch and deal with any exceptions that are thrown by the Email control.

If one or more of the To or cc recipients is determined to be invalid by the local mail server, an exception may be thrown immediately. However, if the invalid recipients can only be detected by the destination mail server, this is out of the scope of the Email control. We recommend that the From address be a mailbox for handling messages bounced back to the sender.

If one or more of the attachment file names is not found, an exception is thrown.