> For the complete documentation index, see [llms.txt](https://jasp402.gitbook.io/easy-yopmail-v4/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jasp402.gitbook.io/easy-yopmail-v4/writemessage.md).

# writeMessage()

This feature allows you to write and send messages.

**Description:**

The `writeMessage()` function of Easy-YOPMail v4 enables developers to programmatically send an email from a specified YOPmail email address to any other recipient. This feature is especially useful for automated testing scenarios where you might need to simulate sending emails or for any other use case where sending an email from a temporary address is beneficial.

**Practical Use:**

Sending an email from a YOPmail address is beneficial in situations such as:

* **Software Testing**: During automated tests, you can use `writeMessage()` to simulate sending emails and then verify if the recipient system processes them correctly.
* **Temporary Communications**: If you need to send a one-off email without revealing your primary email address, this function allows you to do so from a temporary YOPmail address.

**Example Code:**

```javascript
const easyYOPmail = require('easy-yopmail');

let mail = 'sender_email_address@yopmail.com';
let to = 'recipient_email_address';
let subject = 'Sample Subject';
let body = 'This is the body of the email message.';

easyYOPmail.writeMessage(mail, to, subject, body).then(response => {
    console.log(response); // Sample output might vary based on the function's implementation.
});
```

## **Parameters:**

The `writeMessage()` function requires four mandatory parameters:

* <mark style="color:red;">`mail`</mark>: The YOPmail email address from which you want to send the message.
* <mark style="color:red;">`to`</mark>: The recipient's email address.
* <mark style="color:red;">`subject`</mark>: The subject of the email message.
* <mark style="color:red;">`body`</mark>: The body or content of the email message.

## **Error Handling:**

If any of the parameters are missing or invalid, or there's any other issue while trying to send the email, the function might return an error or a specific response indicating the failure. It's crucial to handle these outcomes in your code to ensure smooth execution and provide appropriate user feedback.

## **Limitations:**

As `writeMessage()` uses a YOPmail address to send emails, there might be limitations imposed by YOPmail itself, such as rate limits or restrictions on sending to certain domains. It's essential to be aware of these when using the function.

***

Do you find this format and content suitable for documentation? If there is anything you would like to improve or add, please let me know. <https://github.com/jasp402/Easy-YOPmail/issues/new/choose>
