0

I have found erratic behaviour on the part of Yahoo! mail on the interpretation of subject lines when the header is encoded in base64 and makes more than 2 lines, for example :

Subject: =?UTF-8?B?4pyIIEFvIFN1bCBkYSBBbcOpcmljYSDimIUgVGFyaWZhcyBFeGNs?=
    =?UTF-8?B?dXNpdmFzIOKYhSBQYXJjZXJpYSBMQVRBTSAmIEFlcm9sw61uZWFzIEFyZ2Vu?=
    =?UTF-8?B?dGluYXM=?=

in order to isolate the bug, I would like to be able to send to myself emails with the headers I want, i.e. where I could control myself what appears in the plain-text version of the email that is sent.

Is there any way for me to be able to control this ?

I am using several webmail tools, but there is no way to control what appears in the headers, and I googled for a custom solution with no avail.

1 Answer 1

1

In PHP

That way you can really have a lot of control.

By using PHP PEAR you could do something like this:

$_SMTP = array(
    "host"      =>  "ssl://smtp.gmail.com",
    "username"  =>  "[email protected]",
    "password"  =>  "password123",
    "port"      =>  "465",
    "auth"      =>  true
);

include_once('PEAR.php');
include_once('Mail.php');
include_once('Mail/mime.php');

$mime = new Mail_mime();
$mime->_build_params['html_charset']='UTF-8';
$mime->_build_params['text_charset']='UTF-8';
$mime->_build_params['head_charset']='UTF-8';
$mime->_build_params['head_encoding']='base64';

$mime->setTXTBody("Plaintext message");
$mime->setHTMLBody("<b>HTML message</b>");

$hdrs = array(
    'From'      => '"Me" <[email protected]>',
    'Subject'   => "Test message",
    'To'        => '"Example" <[email protected]>'
);

$body = $mime->get();
$headers = $mime->headers($hdrs);

$mail =& Mail::factory('smtp', $_SMTP);

$result = $mail->send('"Example" <[email protected]>', $headers, $body);

print_r($result);

In fact, you can even print_r($headers); to give you some impression of them even before you send. There are more options to tinker with this, so you might want to research this.

In python

It is also possible to do so in python, using the base libraries email and smtplib as described here

The main idea is to set the header, and you can set the value in plain text using :

msg = MIMEText("text of the mail",'plain')
msg['Subject'] = "=?utf-8?b?Y2Fmw6k=?="

or to generate a proper format from a text :

msg = MIMEText("text of the mail",'plain')
msg['Subject'] = Header("café","utf8")
4
  • Well I don't know PHP but it's a good occasion to learn something new today... Hold my PEAR, I'm going in! I'll let you know if I manage :) Commented Sep 1, 2016 at 22:49
  • 1
    Sure, let me know how it goes. If you are not very familiar with this, you can probably benefit from a XAMP (Windows) or LAMP (Linux) pack, which includes the web server, PHP (most likely with PEAR already installed), MySQL and everything you need to start making websites or research tools discussed above : ) Good luck! Commented Sep 1, 2016 at 22:51
  • 1
    OK I got scared of PHP, and I implemented your solution in python with the email library. It worked perfectly. What should I do now : add a snippet of my python solution to yours, and then accept it ? Commented Sep 2, 2016 at 2:01
  • Yeah, I think that sounds good : ) Commented Sep 2, 2016 at 2:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.