q-coding in addCustomHeader with List-Unsubscribe link - phpmailer

I have a problem with PHPMailer and List-Unsubscribe header.
According to the documentation I am trying to add a header for unsubscribing from emails in the mail UI:
$mail->addCustomHeader("List-Unsubscribe", '<'.$unsubscribe_uri.'>');
In general, the unsubscribe link looks like:
$mail->addCustomHeader("List-Unsubscribe", '<https://example.com/unsubscribe?ddd=asfsfsdf-asdfasfsaafasfsafsfsdfsdfdsfsdf>');
but in the incoming letters in the headlines I see:
List-Unsubscribe: =?us-ascii?Q?<https://example.com/unsubscribe/=3Fddd=3Dasfsfsdf-asdf?=
=?us-ascii?Q?asfsaafasfsafsfsdfsdfdsfsdf>?=
I understand that PHPMailer strives to comply with RFC 2047, but the largest sites (twitter, facebook, paypal) in their newsletters do not encode unsubscribe links.
Yandex-mail technical support directly replied that it is better to avoid q-coding in The list-Unsubscribe header in emails.
How to be, colleagues?

Related

Is there a way to access flights information in GMail API?

When you buy a flight and receive a confirmation email, GMail recognizes it's a flight and adds departure/return tabs at the top of the message.
Using GMail API, I would like to use that information to get all flights from my inbox. Is this possible?
Content that is outside the message body of an email is not accessible from the GMail API. So you won't be able to access the info in any auto-generated tabs.
However, GMail may have auto-labeled the messages as "Travel". If that's the case then you can leverage the GMail API to filter messages using the "Travel" label.
You'll then have to parse the email message for the desired information.
Writing a custom parser can be difficult. However, if the message is annotated so that it conforms to specifications outlined by Google and Schema.org, parsing flight information will be considerably easier. One can assume that flight confirmation messages that trigger the auto-generation of those tabs have flight/reservation specific mark-up embedded within them (but you should probably verify that the email contains said mark-up all the same).
The following links discuss how vendors should embed these special mark-up into their messages:
https://developers.google.com/gmail/markup/getting-started
https://developers.google.com/gmail/markup/reference/flight-reservation#basic_flight_confirmation
You should be able to use those docs to build a custom parser that can detect and parse the required mark-up schema or better yet leverage an open-source library to do so.

Unsubscribe link not shown in gmail

Am sending a mail to gmail.com with a header.
MimeMessage.addHeader("List-Unsubscribe","<http://www.example.com>");
Eventhough the header is present in original content of the mail, unsubscribe link is not shown in mail. Kindly advice.
As my understanding from Google Support Link you need to have prepare some conditions like your try and Amazon Recommendation but finally google decided for show unsubscribed link in top of your emails.
Also, based on Official Gmail Blog:
This only works for some senders right now. We're actively encouraging
senders to support auto-unsubscribe — we think 100% should. We won't
provide the unsubscribe option on messages from spammers: we can't
trust that they'll actually unsubscribe you, and they might even send
you more spam. So you'll only see the unsubscribe option for senders
that we're pretty sure are not spammers and will actually honor your
unsubscribe request. We're being pretty conservative about which
senders to trust in the beginning; over time, we hope to offer the
ability to unsubscribe from more email.
How did you expect it to be shown? Where did you look for it?
Gmail, like most mail readers, doesn't show raw headers. It shows the header information it thinks is relevant. If you want to see the raw headers, there should be a "view source" or "show headers" operation to see them. If you view the message source, and this header is not present, then some mail server has removed it.

Image next to Contact name in Google's Inbox

When receiving emails in Google's Inbox, usually you get as image a coloured circle with the first letter of the contact's mail.
But in rare occasions, there will be an image placeholder, like for instance the example I paste for YouTube. (I know YouTube is owned by Google, but I have seen many other examples)
Is it possible for me to make my own address to have its own image, when someone received an email in Inbox? If so, how?
In Short, this is because you likely don't have a Google+ page with a linked domain matching your email address.
The longer version: Link is here...
EDIT: Seems like this is not a popular answer...
Here's a fuller version:
This Article seems to provide a good overall answer. I'll do a quick summary here.
As a takeaway:
Ensure your site is verified on Google+. This is done in Webmaster tools(link), and your webmaster must approve.
Ensure you have adequate email traffic (seems around 1k a week should do it).
When sending from a domain not matching Google+, you'll need to include a snippet of code in your email, and have Gmail approve the link.
Ensure that your email is authenticated against your domain and not your ESPs (or use the Featured Image markup).
This questions is related: Email Sender Image from Google+ Account

Cannot keep messages in the same conversation due to missing MESSAGE-ID header at Gmail

At some messages in Gmail, the MESSAGE-ID header is missing and I need to use it as IN-REPLY-TO header when replying so I can keep the replies at the same conversation.
When those emails with missing MESSAGE-ID header are replied from the Gmail's WEB UI, the replies stay with the conversation and the reply in fact acquires a IN-REPLY-TO header something looks like <-4185615914882731559#unknownmsgid> I could not discover how is this generated.
I've been trying to find a solution to this problem quite a while, ended up trying a few desktop email clients, Airmail and Sparrow to see how they behave. If I ever reply a particular email which is missing the MESSAGE-ID header using those email clients, the sent reply also acquires the same IN-REPLY-TO header <-4185615914882731559#unknownmsgid> and the reply indeed stays at the same conversation as expected.
So, I would like to ask how they achieve this, do they somehow generate the IN-REPLY-TO header <-4185615914882731559#unknownmsgid>? Is there a rule or a workaround?
This is a classic problem, every mail reader has it. The classic solution is:
copy the References field from the message you reply to, if any.
make up an In-Reply-To field, perhaps with a made-up message-id, perhaps with the sender's address and the message's date.
Keep the subject, and append "re: ".
You may also copy the Thread-Index field, if there is one.
Gmail's and most other threading algorithms will then connect the dots.
Thread-Index is a Microsoft thing, noone else uses it, as far as I know. The format of the hex blob is not specified, but copying that will help probably help Exchange, if the original message comes from Exchange.
If you just want to send an email and make sure it threads with another email in that user's inbox (and not any other gmail users that may receive the reply) then I believe you can use the Gmail API's messages.send() method and set the message.threadId to match the thread you want it to thread with.
I don't think that e-mails delivered to your gmail account have no message id. My evidence is that I just tried sending one to myself via telnet without a message id, and gmail's mx server added this
Message-Id: <54412844.63bbb40a.0772.ffffcbdcSMTPIN_ADDED_MISSING#mx.google.com>
It may be that copying a message into gmail's imap store can result in a missing message id. Eg see https://productforums.google.com/forum/#!topic/gmail/w5kgRivwbIg (though that is very old, it shows that synchronising mail to a gmail IMAP account can have this result).
The basic rule of e-mail is that if an e-mail doesn't have a message id for whatever reason, one is created for it, which is what has happened here. Hence, when you reply, the made-up message id is used in the in-reply-to header.

SMTP Client - Send hidden information that can come back in a reply

I am using the nodemailer SMTP node module, a simple way to send emails through SMTP.
I am using this to send out text messages to various cell carriers, which will allow you to send a text message for free via email. An example email, which will text the Sprint phone (310) 987-6543:
3109876543#messaging.sprintpcs.com
These are all going out through one SMTP email address. This means all text replies from someone's phone will channel back to my email address.
A lot of people send these texts. I want to route the reply text back to the right person, using my own server side code.
The problem is distinguishing where the text came from. Ideally I could hide my own primary key ID for the sender in some sort of SMTP header, which would arrive at the recipients phone and come straight back in their text reply.
I don't really know anything about SMTP or email protocols - is this possible?
edit
As given in each of the answers below, in better email servers you can address to an email address as well as an extension to that address, such as:
// original email
sms-service#mysite.com
// extension
sms-service+a6e1087b#mysite.com
This would be a correct answer and would solve my problem, if only this worked in Exchange Server, which is the email server I am using. I don't know if there is a way to enable this or any other workaround.
Exchange server doesn't support plus addressing natively but it is possible do achieve this with a custom MTA, e.g. http://durdle.com/regexcatchall/
Source: https://serverfault.com/questions/195276/does-exchange-support-plussed-users-e-g-mynamespamexample-com-or-a-similar
Here are a few approaches that you might be able to use:
Unique from addresses
You could you use unique "from" or "reply-to" address for each each message (or for each recipient). For example "sms-service+a6e1087b#mysite.com". In that example, the hex would be a unique identifier that can be mapped to the conversation in your database.
Gmail supports such a scheme: emails targeted to [foo]+[whatever]#gmail.com will be delivered to [foo]#gmail.com and the receiver will know also get the [whatever] back. (more on this http://lifehacker.com/144397/instant-disposable-gmail-addresses)
Identify the user, not the conversation
One option is to not identify the conversation, but identify the phone number the reply comes back from instead. In many cases, the number from where the SMS reply was sent back from is enough to connect that message to the conversation. I'm sure the SMS gateway you're using will provide you with the number from where the reply came from.
Commercial SMS gateway
You can also opt to use a commercial SMS gateway (smsglobal.com comes to mind, though there are many others). These services have well defined APIs for sending a receiving replies. This naturally comes at a price, though. But along with the price, you do get more confidence as to the reliability of the service. A free SMS gateway might get shut down without much warning.
This common problem is traditionally implemented using the semantics of From: and Reply-To: headers of e-mails. This is in fact not (directly) related to SMTP, but rather to ARPA network text messages.
RFC 5322 is the current specification of these messages. It states:
When the "Reply-To:" field is present, it indicates the address(es) to which the author of the message suggests that replies be sent. In the absence of the "Reply-To:" field, replies SHOULD by default be sent to the mailbox(es) specified in the "From:" field unless otherwise specified by the person composing the reply.
So you simply need to encode the information you need into the Reply-To: header. Since you mention your own server-side code, you might be running an SMTP server yourself. In this case, you can put any address that will be routed to your SMTP server and encode the right person's address there.
Alternatively, if you rely on another SMTP server, you might want to use aliases. Postfix, and mail services such as GMail, typically allow address extensions, i.e. addresses of the form user+foo#domain.com, and you can encode the necessary information in the address extension.
For example, let's say that alice#domain.com wants to send a text to Sprint phone (310) 987-6543 through your service, you could send an e-mail to 3109876543#messaging.sprintpcs.com with:
Reply-To: alice%40domain.com#yourservice.com
Alternatively:
Reply-To: yourservice+alice%40domain.com#gmail.com
This will allow you to route the reply properly by looking at the destination of the reply e-mail.

Resources