41

I'm using aws-sdk-for-php and using AmazonSES for sending email. The problem is I want to set the name for the email. Example:

指定 < email_address >

Here my source code:

$mailer = new \AmazonSES( $aws_config ); $response = $mailer->send_email($mail_data['from'],$mail_data['to']);
yivi
  • 42,438
  • 18
  • 116
  • 138
Mr.Coi
  • 437
  • 1
  • 4
  • 6

5 Answers5

96

I believe the format you're looking for is as follows:

"John Doe" <johndoe@example.com>

Reference: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/email-format.html

dezinezync
  • 2,730
  • 21
  • 15
  • 3
    Yes, thanks you. But I have another problem if name is not English character. How can I use with name such as 指定 – Mr.Coi Mar 03 '14 at 07:45
  • So turns out, by default, only ASCII characters are allowed for that. So the Chinese string wouldn't work. Although, it does sound possible using the RFC 2047 Encoding as mentioned in here: http://docs.aws.amazon.com/ses/latest/APIReference/API_Destination.html – dezinezync Mar 03 '14 at 08:15
  • Did you ever find out how to change the encoding ? – Sahan Jul 11 '16 at 08:32
  • @Sahan you cannot change the encoding. Maybe because how email systems are configured and written, ASCII is the only one supported. – dezinezync Jul 11 '16 at 09:05
  • 1
    for an example of this in code look here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/examples-send-using-sdk.html – Samuel Mburu Nov 16 '21 at 21:01
  • 1
    @Sahan I found out how. You have to send the name encoded with MIME encoded-word syntax. "指定 " would be "=?utf-8?B?5oyH5a6a?= " – Augusto Jara Jan 16 '23 at 18:38
6

I have resolved the same issue after checking this aws forum link . I was using aws SES for sending mails using java sdk , so I have added the from email id in the application.yml file like below.

from: John Doe <johndoe@example.com>
Vignesh_A
  • 508
  • 1
  • 7
  • 19
0

SES doesn't support Japanese characters by default, so you have to encode from name with iso-2022-jp encoding.

below is sample in python.

from email.header import Header
import os

FROM_ADDRESS = os.environ.get('FROM_ADDRESS')
FROM_NAME = os.environ.get('FROM_NAME')

...
from_address = '{} <{}>'.format(Header(FROM_NAME.encode('iso-2022-jp'),'iso-2022-jp').encode(), FROM_ADDRESS)

ToanNV
  • 56
  • 1
  • 2
0

Short answer:

You have to send the name encoded with MIME encoded-word syntax.

"指定 <johndoe@example.com>" would be "=?utf-8?B?5oyH5a6a?= <johndoe@example.com>"

Long Answer:

Althoug @dezinezync answer is correct, it only works for non-ASCII characters so if you want to set a friendly name as "指定" or any other (my problem was with spanish/latin characters "á, é, í, ó, ú" showing the symbol � instead) you have to encode the string.

Acording to amazonSES javascript SDK Docs

The sender name (also known as the friendly name) may contain non-ASCII characters. These characters must be encoded using MIME encoded-word syntax, as described in RFC 2047. MIME encoded-word syntax uses the following form: =?charset?encoding?encoded-text?=.

So using utf-8 and base64 encoding you will be able to set the name you need.

Encoding 指定 to base64 will give you this string 5oyH5a6a and based on the RFC 2047 MIME encoded-word-syntax you have to replace the encode-text in the form:

=?charset?encoding?encoded-text?= <email@domain.com>

Resulting:

=?utf-8?B?5oyH5a6a?= <email@domain.com>

Where =? marks the begining and the end of the encoded string, utf-8 is the charset (which support japanese characters) and the B is the encoding, can be either "Q" (denoting Q-encoding) or "B" (denoting base64 encoding) and finally 5oyH5a6a the base64 string that represents 指定.

Thats it! :)


Here is code I found in php (haven't test it) that uses the Q-encoding:

<?php
$name = ""; // kanji
$mailbox = "kru";
$domain = "gtinn.mon";
$addr = mb_encode_mimeheader($name, "UTF-7", "Q") . " <" . $mailbox . "@" . $domain . ">";
echo $addr;

Here is the link of the code https://doc.bccnsoft.com/docs/php-docs-7-en/function.mb-encode-mimeheader.html

And other references:

https://nerderati.com/2017/06/09/mime-encoded-words-in-email-headers

https://knowledge.ondmarc.redsift.com/en/articles/2720905-multipurpose-internet-mail-extensions-mime#:~:text=The%20MIME%20encoded%2Dword%20syntax,the%20charset%20into%20ASCII%20characters.

Hope it helps!

-3

I only changed the format and it is working fine for me.

"from": {
   "name": "name",
   "address": "email address"
}
Cray
  • 2,774
  • 7
  • 22
  • 32
tamil arasan
  • 57
  • 1
  • 2