> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/wordpress/use-cases/how-to-translate-email-sending-by-plugin-wp-mail-smtp.md).

# How to translate email sending by plugin WP Mail SMTP

{% hint style="info" %}
Weglot can translate `wp_mail` emails natively — just enable the **Translate emails** option in the Weglot settings. Use the snippet below only if you need custom handling on top of the built-in option (for example with WP Mail SMTP).
{% endhint %}

This example translates the email message body into the current language:

```php
function wp_mail_smtp_weglot( $args ) {
	$original_lang    = weglot_get_original_language();
	$current_language = weglot_get_current_language();
	if ( $original_lang == $current_language ) {
		return $args;
	}

	if ( ! empty( $args['message'] ) ) {
		$translate_service = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
		$translate_message = $translate_service->translate_pdf( $args['message'], $current_language );
		$args['message']   = $translate_message['content'];
	}
	return $args;
}

add_filter( 'wp_mail', 'wp_mail_smtp_weglot', PHP_INT_MAX );
```
