---
title: c Mail
description: Available connectors
documentId: ipaas-mail
locale: en-US
---

The [**Mail**](https://camel.apache.org/components/4.10.x/mail-component.html) component is used to send and receive emails. It is often divided into three main protocols:

- **IMAP** for accessing and managing emails on the server.
- **POP3** for downloading emails from the server.
- [**SMTP**](#smtpsmtps) for sending emails.

## SMTP/SMTPS

[**SMTP**](https://camel.apache.org/components/4.10.x/mail-component.html) is used to send emails to SMTP servers, allowing Camel to send messages with custom content, attachments, and recipients in an integration flow.

<Callout type="note" title="NOTE">
**SMTPS** is a secure version of SMTP that transmits encrypted data using SSL/TLS.
</Callout>

**URI Syntax**: `smtp:host:port` or `smtps:host:port`

### Main fields

*Path parameters*

| **Name** | **Description** | **Default** | **Type** |
|----------|------------------|------------|----------|
| `host` (common) |(required) The mail server host name.| — | String |
| `port` (common) | The port number of the mail server. | — | int    |

<Callout type="note" title="NOTE">
If the port number is omitted, Camel determines the port number to use based on the protocol.

|Protocol|	Default port number|
|--------|---------------------|
|SMTP    | 25                  |
|SMTPS   | 465                 |

</Callout>

*Query parameters*

| **Name** | **Description** | **Default** | **Type** |
|----------|-----------------|-------------|----------|
| `username` (security)   | The username for login.                       | —               |String  |
| `password` (security)   | The password for login.                       | —               |String  |
| `from` (producer)       | The from email address.                       | camel@localhost | String |
| `to` (producer)         | Sets the destination email address. Separate multiple email addresses with comma.| —  |String|
| `subject` (producer)    | The subject of the message being sent.         | —              | String |
| `contentType` (advanced)| The mail message content type. Use text/html for HTML mails. | text/plain  | String |

### Example

This flow demonstrates how to receive an HTTP request, compose an email from the received data, and send it using the SMTPS protocol (port 465), logging the operation at the end of processing.

<Steps>
  <Step>
  The flow receives a POST request.
  </Step>
  <Step>
   Defines the email headers:
   - **To**: recipient (john.doe@sensedia.com)
   - **Subject**: subject "[POC - Camel Mail] Camel is cool"
   - **Content-Type**: plain text (`text/plain`)
  </Step>
  <Step>
  Then, composes the email body, including the content received in `rest.body`.
  </Step>
    <Step>
  Converts the body to `java.lang.String`, ensuring compatibility with the email component.
  </Step>
  <Step>
   Then sends an email via SMTPS (Gmail on port 465) with configured credentials.
   </Step>
  <Step>
  Finally, logs a message indicating the operation completion.
  </Step>
</Steps>

```yaml
- from:
    uri: rest:post:hello
    steps:
      - setHeader:
          name: To
          expression:
            constant:
              expression: John Doe <john.doe@sensedia.com
      - setHeader:
          name: Subject
          expression:
            constant:
              expression: "[POC - Camel Mail] Camel is cool"
      - setBody:
          expression:
            simple:
              expression: "Trying to append rest.body in this email body: ${body}"
      - setHeader:
          name: Content-Type
          expression:
            constant:
              expression: text/plain
      - convertBodyTo:
          type: java.lang.String
      - to:
          uri: smtps:gmail:465
          parameters:
            password: xxxxx hhhh zzzz
            username: poccamelcomponentst@gmail.com
      - to:
          uri: log:INFO
```

![](https://creative-ball-51b3fc85c0.media.strapiapp.com/component_smtps_5c63154530.png)


#### cURL

```
curl --location --request POST 'https://sensedia-integration-camel-poc.f6g7h8i9j0.integrations-tst.sensedia-eng.com/hello' \
--header 'Content-Type: application/json' \
--data-raw '{
    "names": [
        "joao",
        "maria",
        "pedro",
        "ana"
    ]
}'
```

#### Result

```
sensedia-integration-camel-poc-00001-deployment-6df65649dbxvglx integration 2024-03-12 12:25:28,029 INFO  [info] (executor-thread-1) Exchange[ExchangePattern: InOut, BodyType: String, Body: Trying to append rest.body in this email body: {    "names": [        "joao",        "maria",        "pedro",        "ana"    ]}]
```

# Sending emails with attachments

To send emails with attachments, use the EIP [**Process**](/docs/integrations/ipaas-eips-process).

The processor allows you to define: the attachment name, content-type, and content, which can be binary or text.

See an example below:


<Steps>
  <Step>
 **Flow start**: the flow starts with a GET request to the `/mail` endpoint.
  </Step>
  <Step>
    **Document retrieval**: the flow makes a GET request to an external API to obtain the contents of a file (PDF). The `bridgeEndpoint: true` parameter ensures that headers will be preserved. The returned content is stored in the message body.
  </Step>
  <Step>
   **Attachment headers preparation**: three custom headers are defined with the file information:

  -  `SensediaAttachmentName`: defines the file name ("notafiscal.pdf").
  - `SensediaAttachmentContentType`: defines the MIME type of the file ("application/pdf").
  - `SensediaAttachmentContent`: the binary content of the file (taken from the current body using `${body}`).

<Callout type="note" title="NOTE">
MIME type (Multipurpose Internet Mail Extensions) identifies the format of a file (e.g., application/pdf, image/jpeg, text/html) so that systems know how to interpret it correctly.
</Callout>
 </Step>
 <Step>
**Processing**: uses the `AddAttachmentProcessor` to add the attachment to the email based on the defined headers.
  </Step>
  <Step>
   **Email body**: defines the text that will appear in the message body.
  </Step>
  <Step>
   **Header removal**: removes temporary headers so they are not sent to the SMTP server.
  </Step>
    <Step>
  **Sending**: connects to Gmail's SMTP server and sends the email with the attachment.
  </Step>
  <Step>
  **Response**: returns a confirmation message to the client.
  </Step>
</Steps>


```yaml
- from:
    uri: rest:get:/mail  #flow start
    steps:
      #document retrieval
      - toD: 
          uri: https://example-api-sensedia.com/sandbox/puxxxx/v1/documents/67948333232/content
          parameters:
            bridgeEndpoint: true 
            httpMethod: GET
      #attachment headers preparation
      - setHeader: 
          name: "SensediaAttachmentName"
          expression:
            constant: "notafiscal.pdf"
      - setHeader:
          name: "SensediaAttachmentContentType"
          expression:
            constant: "application/pdf"
      - setHeader:
          name: "SensediaAttachmentContent"
          expression:
            simple: ${body}
      #processing
      - process: 
          ref: "#class:com.sensedia.ipaas.camel.processor.AddAttachmentProcessor"
      #email body
      - setBody:
          expression:
            constant: "Este é o corpo do email"
      # header removal
      - removeHeaders: "Sensedia*"
      - removeHeaders: "Content-Type"
      # sending
      - to:
          uri: smtps://smtp.gmail.com:465
          parameters:
            username: yourusername@gmail.com
            password: yourpassword 
            from: sender@gmail.com
            to: torecipients@gmail.com
            subject: Email enviado pelo Integrations
            contentType: "text/plain"
            mail.smtp.auth=auth: auth
            mail.smtp.starttls.enable: starttls
      # response
      - setBody:
          expression:
            constant: "Envio realizado com sucesso"
```
