Skip to content

Commit

Permalink
Update SMTP example for non-ASCII words support in subject and body.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Nov 5, 2023
1 parent ecb496f commit 1b22075
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ The minimum ram requirement is based on the applications (SMTP and IMAP). IMAP a
* Support on-board or native networking (WiFi and Ethernet) and external networking (WiFi, Ethernet and GSM) via external basic WiFiClient, EthernetClient and GSMClient.
* Supports TinyGSM library integration.

### Note:

This library does not contain the encoder to handle character encodings of your message envelope e.g. `iso-8859-*` in form of `encoded-words` when sending the message due to code size limit.



Expand Down
39 changes: 26 additions & 13 deletions examples/SMTP/Send_Text/Send_Text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,35 @@ void setup()
message.author.email = AUTHOR_EMAIL; // should be the same email as config.login.email
*/

message.subject = F("Test sending plain text Email");
// In case of sending non-ASCII characters in message envelope,
// that non-ASCII words should be encoded with proper charsets and encodings
// in form of `encoded-words` per RFC2047
// https://datatracker.ietf.org/doc/html/rfc2047

String subject = "Test sending message (中文电子邮件)";
String encoded_subject = "=?utf-8?B?";
encoded_subject += MailClient.toBase64(subject);
encoded_subject += "?=";

message.subject = encoded_subject;

message.addRecipient(F("Someone"), RECIPIENT_EMAIL);

String textMsg = "This is simple plain text message";
String textMsg = "This is simple plain text message with Chinese words (中文电子邮件) in subject and body";

message.text.content = textMsg;

/** The content transfer encoding e.g.
* enc_7bit or "7bit" (not encoded)
* enc_qp or "quoted-printable" (encoded)
* enc_base64 or "base64" (encoded)
* enc_binary or "binary" (not encoded)
* enc_8bit or "8bit" (not encoded)
* The default value is "7bit"
*/

message.text.transfer_encoding = "base64"; // recommend for non-ASCII words in message.

/** If the message to send is a large string, to reduce the memory used from internal copying while sending,
* you can assign string to message.text.blob by cast your string to uint8_t array like this
*
Expand All @@ -255,17 +278,7 @@ void setup()
* utf-7
* The default value is utf-8
*/
message.text.charSet = F("us-ascii");

/** The content transfer encoding e.g.
* enc_7bit or "7bit" (not encoded)
* enc_qp or "quoted-printable" (encoded)
* enc_base64 or "base64" (encoded)
* enc_binary or "binary" (not encoded)
* enc_8bit or "8bit" (not encoded)
* The default value is "7bit"
*/
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
message.text.charSet = F("utf-8"); // recommend for non-ASCII words in message.

// If this is a reply message
// message.in_reply_to = "<parent message id>";
Expand Down

0 comments on commit 1b22075

Please sign in to comment.