Why are my automated confirmation / subscription emails getting flagged as spam in gmail? - ruby-on-rails

So I have a rails app set up with devise that sends out account confirmation and password reset emails. The emails get sent out using the sendmail command using postfix for smtp. I have DKIM set up and gmail is accepting the signatures as valid. I also have SPF set up correctly.
Gmail is giving me this message as an "explanation" of why my emails are getting spammed:
Why is this message in Spam? It contains content that's typically used
in spam messages.
As descriptive as that is, I have no idea what content in particular is typically used in spam messages. I've tried tweaking the text, changing to html, then to text+html, changing the from address, adding the user's full name to the to address in addition to the email. I'm stumped. Maybe another pair of eyeballs can point out something stupid that I've simply overlooked.
The full text of the message follows with personally identifiable information redacted.
Delivered-To: myaddress#gmail.com
Received: by 10.216.199.130 with SMTP id x2csp42610wen;
Sun, 16 Jun 2013 13:16:13 -0700 (PDT)
X-Received: by 10.224.174.6 with SMTP id r6mr13525400qaz.87.1371413772413;
Sun, 16 Jun 2013 13:16:12 -0700 (PDT)
Return-Path: <account-services#booyango.com>
Received: from booyango.com (node1.booyango.com. [97.107.138.232])
by mx.google.com with ESMTP id k6si3223197qcj.4.2013.06.16.13.16.11
for <myaddress#gmail.com>;
Sun, 16 Jun 2013 13:16:12 -0700 (PDT)
Received-SPF: pass (google.com: domain of account-services#booyango.com designates 97.107.138.232 as permitted sender) client-ip=97.107.138.232;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of account-services#booyango.com designates 97.107.138.232 as permitted sender) smtp.mail=account-services#booyango.com;
dkim=pass header.i=#booyango.com
Received: by booyango.com (Postfix, from userid 33)
id 7CEC133DF5; Sun, 16 Jun 2013 20:16:11 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=booyango.com;
s=default; t=1371413771;
bh=iXfBZB6q0fPI+Yms0E8FC1P/T9J+3enBFtTrsjcTADY=;
h=Date:From:Reply-To:To:Subject;
b=AGw4SXj6UN0lpEo0FSO91s3aAYDsmAHZVqBvvYGQPW6Jp1UhfAQFlIE1AYY0CcoUq
Xb3Mn4vul1WXpdWIZMPEgHXJ3SwvEvSxDfDEeYTNiGRoI+DW7vFopTo+1rQeLLdS/B
j6iIKFsJUAOz0n1yh9/gasXJeOv4fmK6+ZoMhLfQ=
Date: Sun, 16 Jun 2013 20:16:11 +0000
From: Booyango Account Services <account-services#booyango.com>
Reply-To: Booyango Account Services <account-services#booyango.com>
To: me <myaddress#gmail.com>
Message-ID: <51be1d0b55c16_44f38e887057054#node1.booyango.com.mail>
Subject: [Booyango] Reset password instructions
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Oops, it looks like you lost your Booyango password.
You can use the following link within the next 24 hours to reset your password:
http://booyango.com/users/password/edit?reset_password_token=<reset_token>
Thanks,
The Booyango Team

I have had problems with this in the past, and found solutions to be largely hit and miss. If the server which is sending your mail happens to be on a black list because of previous spammers linked to your server/IP address, you are probably out of luck. Otherwise, I have had limited success by playing with different header variables; also plain text emails tend to have higher delivery success rates than HTML - in my experience (although, I realise you are already doing this).
Also try rephrasing your subject line or body text, you may just be getting caught by a spam rule looking out for a pattern you have accidently stumbled upon.

I found the my devise or rails emails were sent to gmail span if
1) they included a link (ex. confirmation token)
2) the subject was blank

Related

How do I manage to get the "Unsubscribe" link right next to the From address on Gmail?

I'm working on an email marketing project, and I'm trying to get that link shown on the emails sent from our servers.
I'm including the "List-Unsubscribe: , " header, besides other headers considered good practices by RFC, support.google, ...
Is it possible that we are doing something wrong on the headers construction?
This is the link I'm talking about:
Unsubscribe link
Our headers:
Received: by 10.37.51.2 with SMTP id z2csp2282796ybz;
Tue, 4 Oct 2016 09:32:50 -0700 (PDT)
X-Received: by 10.159.48.147 with SMTP id j19mr2901380uab.45.1475598769950;
Tue, 04 Oct 2016 09:32:49 -0700 (PDT)
Return-Path: <*****************#74344.returnpath.dattanet.com>
Received: from mta107.185.esmkt.net (mta107.185.esmkt.net. [200.58.107.185])
by mx.google.com with ESMTPS id 7si1993119vkg.227.2016.10.04.09.32.48
for <*****************#gmail.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Tue, 04 Oct 2016 09:32:49 -0700 (PDT)
Received-SPF: pass (google.com: domain of bounces-*************=gmail.com#74344.returnpath.dattanet.com designates 200.58.107.185 as permitted sender) client-ip=200.58.107.185;
Authentication-Results: mx.google.com;
dkim=pass header.i=#74344.senders.dattanet.com;
dkim=pass header.i=#gmail.esmkt.net;
spf=pass (google.com: domain of bounces-*************=gmail.com#74344.returnpath.dattanet.com designates 200.58.107.185 as permitted sender) smtp.mailfrom=bounces-***************=gmail.com#74344.returnpath.dattanet.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=esdkim; d=74344.senders.dattanet.com; h=From:Reply-To:List-ID:Sender:List-Unsubscribe:Subject:Content-Type:MIME-Version:To:Date:Message-ID; i=*************#74344.senders.dattanet.com; bh=8JDi/gUM6J+D33yKj8l/4tZW5kFud7LHPmwWlCcrfqU=; b=WPSqCxYnM9WW8keFP8N3R4QZ8LkGIkoT4tftaVM02NsTdY4krn51J4CFG0FvZ8bQhebdqwpg4mTw
SB14IkPGNVNHMgK2+u2q25f4Qa7psu/cc/lPL93ss++9H99JtdSakeimOhbHGy4O2zm9TVgQYiXu
eq/kTZs5pZUuW0/PPek=
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=dkim; d=gmail.esmkt.net; h=From:Reply-To:List-ID:Sender:List-Unsubscribe:Subject:Content-Type:MIME-Version:To:Date:Message-ID; bh=8JDi/gUM6J+D33yKj8l/4tZW5kFud7LHPmwWlCcrfqU=; b=hwo3JCkn4tLxNPZyDkpCc85ND9PMQxlIXKoQqmCERhBwmm70+/Ga53HLlpr82ENHeQ9wklyy26/G
jqAB9wla/JZhaBdL/QiibJZi4VuxuGHsOC3s4FuyU68VWnQLPKySvtMRVPkuD50M0Rz6uFCzWRYz
qkXj08TTGbSWEmu76sA=
Precedence: bulk
X-DM-SENDER: MAILTX
From: *********#********.com
Reply-To: **********#***********.com
X-DM-Tracking-Domain: 1
X-Mailer-CSID: 1BRsE7-1426929
X-DM-Priority: 10
X-Report-Abuse: Please report abuse for this campaign here:
http://envialosimple.com/abuse/
List-ID: <74344:2>
Sender: *******=******.com#74344.senders.dattanet.com
Return-Path: bounces#74344.returnpath.dattanet.com
List-Unsubscribe: <mailto:unsubscribe#74344.track.dattanet.com?body=#s-1key#223bdbd85ee9bc39069593195d9b8adadf8c694a340e311511028f29c29314b078d864a0660e40e88845201193021993d6b3fdec739d1c851b7960b2adb635a27c#e-1key#>, <http://74344.track.dattanet.com/track/click?u=unsubscribe&p=37343334343a3139373a3137383a303a303a30&m=2&s=043258db01b40ed12a95ef7f5f49a2b9>
Subject: **************
Content-Type: multipart/alternative; boundary="=_e61683699dd8c4bbfbaf3f6d4aa2e716"
MIME-Version: 1.0
To: <**************#gmail.com>
Date: Tue, 4 Oct 2016 13:32:47 -0300
Message-ID: <0.0.5.A9F.1D21E5CF13826CA.129B3#mta107.185.esmkt.net>
Thanks in advance!
Even i was trying something like that and found that it is google's which scrapes the data from the Email Body and puts and Unsubscribe link right next to the name.
List-Unsubscribe will and can only ensure that the UNSUBSCRIBE Link is present when you press the downward arrow next to me .
The unsubscribe option is only shown for senders with a high reputation.
See Gmail unsubscribe link does not appear
As far as I know there is already an existing Gmail feature wherein you may opt to add "Unsubscribe" button.
From this Gmail forum, suggested steps are as follows:
Log-in to your Google group.
Click on the Gear icon top right of the home page, from the drop-down select "Group settings".
Click to expand "Settings" in the left panel, and click on "Email Options".
In the right panel, under Email Footer you should be able to spot "Display how to unsubscribe from this group by email".
Check the box to the left of it.
You will be prompted to save your changes on Exit.
Another option is to use this add-on. As noted in the given link, with this add-on, it is your responsibility to add an unsubscribe link to your emails if you think it is needed.
For now on, there is no built-in unsubscribe feature in the add-on. We recommend using Google Form to let people tell you they don't want to receive your emails anymore. People will fill the form, submit their email address and you will be able to remove those email addresses from your mailing list to stop sending them emails.
Steps on how to implement this can be found in this given documentation or you may also check this article for the newer version.

Sending EWS invites with Viewpoint via heroku dyno get blocked by spam filter

I'm using the excellent Viewpoint ruby gem to create an event in my EWS calendar and send invites to attendees, on an heroku app.
This works very well in development, and in heroku production console.
When I do it from an heroku web dyno, the event gets created with correct attendees, but invites are not sent. Instead, I receive an email from exchange server saying my outbound message can't be delivered due to spam detection:
Remote Server returned '550 5.1.8 Access denied, spam abuse detected'
En-têtes de message d'origine :
Authentication-Results: gmail.com; dkim=none (message not signed)
header.d=none;
Received: from AMSPR01MB103.eurprd01.prod.exchangelabs.com (10.242.91.146) by
AMSPR01MB101.eurprd01.prod.exchangelabs.com (10.242.91.140) with Microsoft
SMTP Server (TLS) id 15.1.154.19; Mon, 4 May 2015 09:18:41 +0000
Received: from AMSPR01MB103.eurprd01.prod.exchangelabs.com ([169.254.4.13]) by
AMSPR01MB103.eurprd01.prod.exchangelabs.com ([169.254.4.13]) with mapi id
15.01.0154.018; Mon, 4 May 2015 09:18:40 +0000
Content-Type: application/ms-tnef; name="winmail.dat"
Content-Transfer-Encoding: binary
From: Nicolas Marlier <nicolas#marlier.onmicrosoft.com>
To: "nmarlier#gmail.com" <nmarlier#gmail.com>
Subject: =?utf-8?B?Tm91dmVsIMOpdsOobmVtZW50?=
Thread-Topic: =?utf-8?B?Tm91dmVsIMOpdsOobmVtZW50?=
Thread-Index: AdCGSDTEah5PWrxeqEy/iSmi4R7oNg==
X-MS-Exchange-MessageSentRepresentingType: 1
X-MS-Exchange-Calendar-Originator-Id: 52a7b57c-9423-417c-8560-37fa3ae0e74a;/o=ExchangeLabs/ou=Exchange
Administrative Group
(FYDIBOHF23SPDLT)/cn=Recipients/cn=096fdd7902e244399c6fbd8bf2401533-nicolas
Date: Mon, 4 May 2015 09:18:40 +0000
Message-ID: <AMSPR01MB10304E80D885534965D74C3F7D20#AMSPR01MB103.eurprd01.prod.exchangelabs.com>
Accept-Language: fr-FR, en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator: <AMSPR01MB10304E80D885534965D74C3F7D20#AMSPR01MB103.eurprd01.prod.exchangelabs.com>
MIME-Version: 1.0
X-Originating-IP: [54.163.190.73]
Return-Path: nicolas#marlier.onmicrosoft.com
X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AMSPR01MB101;
X-Microsoft-Antispam-PRVS:
<AMSPR01MB10156182A79CE60E68A4106F7D20#AMSPR01MB101.eurprd01.prod.exchangelabs.com>
X-Exchange-Antispam-Report-Test: UriScan:;
X-Exchange-Antispam-Report-CFA-Test:
BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:AMSPR01MB101;
X-Forefront-PRVS: 05669A7924
I'm thinking this may be caused by the heroku instance not being whitelisted, and I'm considering trying something like the Proximo add-on to fix that. Any thought on another way to make sure the invite is being sent ?

How to use CATENATE command in IMAP

Already been through RFC 4469.
Just wanted to know how exactly I can use the CATENATE command.
I also referred the example given in the RFC. But couldn't really execute it against the server.
Any help will be appreciated.
I know this is old issue, but since I was looking this myself, and noticed this I thought I'd share what I found.
So. The simple examples:
s SELECT INBOX
a APPEND INBOX (\Seen) CATENATE (TEXT {53+}
Date: Tue, 03 Jan 2017 22:39:40 +0200
Hello, world.
)
This will work with modern system. You can also use
s SELECT INBOX
a APPEND INBOX (\Seen) CATENATE (TEXT {53}
Date: Tue, 03 Jan 2017 22:39:40 +0200
Hello, world.
)
The thing about catenate is that it can also combine input from other emails. You can do this with URL.
a APPEND INBOX CATENATE (URL "/INBOX;UIDVALIDITY=1483364905/;UID=2/;SECTION=HEADER" TEXT {8}
Hello..
)
a OK [APPENDUID 1483364905 4] Append completed.
FETCH 4:4 (BODY[])
Date: Tue, 03 Jan 2017 22:39:40 +0200
Hello..
)
a OK Fetch completed.
And we have reused headers from mail with UID 2 in INBOX. UIDVALIDITY can be acquired by saying s STATUS INBOX.
The examples in the IETF are bit spooky, but they show how to use mime multipart as input.

How to get subject, content, etc fetched via Net::IMAP

I'm facing trouble decoding messages fetched through ruby's Net::IMAP, here's what I've tried in console
imap = Net::IMAP.new(‘imap.gmail.com’,993,true)
imap.login(“my#gmail.com”, “mypassword”)
imap.select(‘INBOX’)
msgs = []
imap.uid_search(["NOT", "DELETED"]).each do |uid|
msgs << imap.uid_fetch(uid, ['RFC822']).first.attr['RFC822'].to_s
end
Now when I'm doing msgs.first I'm getting this
"Return-Path: <my#gmail.com>\r\n
Received: from 192.168.10.191:3000 ([111.93.167.67])\r\n
by mx.google.com with ESMTPSA id kz4sm35619700pbc.39.1969.12.31.16.00.00\r\n
(version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\r\n
Thu, 05 Sep 2013 06:18:24 -0700 (PDT)\r\n
Date: Thu, 05 Sep 2013 18:48:18 +0530\r\n
From: my#gmail.com\r\n
Reply-To: please-change-me-at-config-initializers-devise#example.com\r\n
To: admin#example.com\r\n
Message-ID: <5228849ab79c5_4b57133029c665c4#rajde1.mail>\r\n
Subject: Confirmation instructions\r\n
Mime-Version: 1.0\r\n
Content-Type: text/html;\r\n
charset=UTF-8\r\n
Content-Transfer-Encoding: 7bit\r\n\r\n
<p>Welcome admin#example.com!</p>\r\n\r\n<p>You can confirm your account email through the link below:</p>\r\n\r\n<p>Confirm my account</p>\r\n"
How to decode this, please help. I'm new to this feature.
When you retrieve RFC822 you get the whole thing. If you retrieve BODY.PEEK[HEADER.FIELDS (Subject)] you'll get just the subject. (There's also an ENVELOPE which can be quite handy, it contains Subject, From and a few more, neatly parsed for you.) Fetching the body (I assume that's what you mean by content) is a little more tricky, you need to first retrieve the bodystructure, then retrieve the parts you want, often BODY.PEEK[1] or BODY.PEEK[1.2] or somesuch.
Try using something like this:
body1 = imap.fetch(uid, "RFC822")[0].attr["RFC822"]
mail = Mail.new(body1)
subject = mail.subject
to = mail.to
like that you could take all the value.

Sending 1 attachement, recipients reports 2 attachements (ATT0001.c added) - Rails 3, ActionMailer

To exchange data with another system we send the data as an email attachment to a dedicated address. The email is generated using ActionMailer v3.2.12.
The problem is that when the email arrives at its destination, a redundant attachment named ATT00001.c is a part of the email, in addition to the attachment we created. This causes issues with the import routine at the other end.
A big part of the problem is that we know almost nothing about how the email is being handled at the destination . We also dont know what type of email server is in use and dont have access to check what the email actually looks like when it arrives. We can send it to one of our own addresses and it looks fine there.
I know this is not a lot to go on, but perhaps one of you guys have seen these ATT00001-attachments being added to machine generated emails before.
config.action_mailer.smtp_settings
address: smtp.<mailprovider>.com
port: 587
domain: ourdomain.com
authentication: login
user_name: <removed>
password: <removed>
enable_starttls_auto: false
Update:
We've been able to obtain a copy of the problematic email and it shows the email body rendered after the attachment as an attachment of its own.
We've tried setting ActionMailer's parts_order to make sure the attachment is generated after the email body, it did not help.
Update2:
Sending to my gmail account and showing original raw data I get this.
SENT MAIL
in receipt response from recipient to the correct attachment (the autocreated one creates an error log entry)
(...) cut: to from and through email header information
Mime-Version: 1.0
Content-Type: multipart/mixed;
charset=UTF-8
Content-Transfer-Encoding: 7bit
--
Date: Thu, 28 Feb 2013 12:15:23 +0100
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="thefile.mscons"
Content-ID: <512f3c4b6e875_a8f756dcc642fe#bjorns_arch.mail>
VU5BOisuPyAnVU5CK1VOT0M6Mys3MDgwMDAzNDExNzE2OjE0OlRJTUVSKzcw
... many more lines like this ...
ODAwMDUwNTEyMTc6MTQ6VElNRVIrMTMwMjI4OjEyMTUrUE9XRVNUMTMwMjI4
----
This is with body nil in actionmailer
Next is a RESPONSE from the recipient system, sent to my gmail. It's a receipt on the correct attachment (the extra attachement generates an error, flushing their system)
RECEIVED MAIL
(..) unintersting header stuff with addresses
Content-Disposition: attachment;
filename="afilename.txt"
Content-Transfer-Encoding: base64
Content-Type: Application/EDIFACT; charset="iso-8859-1"
Mime-Version: 1.0
Date: Sat, 16 Feb 2013 11:07:10 +0100
From: ediel#example.com
To: ***#gmail.com
Subject: thesubject
Message-ID: <511f5a53.850a700a.2fa0.2a0eSMTPIN_ADDED_BROKEN#mx.google.com>
X-TM-AS-Product-Ver: IMSS-7.0.0.6298-6.8.0.1017-19380.002
X-TM-AS-User-Approved-Sender: Yes
X-Greylist: Sender is SPF-compliant, not delayed by
milter-greylist-4.0 (isp-app27-vm.isp.example.com [213.239.116.46]);
Sat, 16 Feb 2013 11:07:11 +0100 (CET)
X-ExampleIKT-MailScanner-Information: Please contact the ISP for more information
X-ExampleIKT-MailScanner-ID: r1GA7BqD021150
X-ExampleIKT-MailScanner: Found to be clean
X-ExampleIKT-MailScanner-From: ediel#example.com
X-Spam-Status: No
VU5BOisuPyAnVU5CK1VOT0M6Mys3MDgwMDA1MDUxMjE3OjE0OlRJTUVSKzcwODAwMDM0MTE3MTY6
.. more..
pUSU1FUisxJ1VOVCszKzEnVU5aKzErMjAxMzAyMDAyNDg1Nzcn
something suspicious with the Content-Type? Is a new (empty) attachment generated from the stuff prior to -- in the sent email?
I believe this is to do with inline attachments and Exchange server. Some clients, Apple Mail in particular allow you to add inline attachments, that is, a MIME attachment sandwiched in between text/body parts of an email. Exchange server expects that all attachments appear after any text portion of a mail.
Everything after the attachment in your mail gets treated as an attachment, so the body gets stuffed into a file and named as you reported it to be named. Seeing as you're using ActionMailer, see this answer and possible this answer, which explains that you need to switch the order of the lines of code, and possibly play with some other settings.
Our problem is solved, though unfortunately I cant say what caused the redundant attachment. We worked around it by sending a non-multipart email that contained only the attachment. This solution obviously wont work for people who need to send a multipart email.
Sending non-multipart email with an attachment in Rails is not straight forward. You cant use the attachment helper method and a blank body, you need to put the attachment content in the email body and manually specify the disposition.
class MailMan < ActionMailer::Base
def test
attachment_content = "my attachment"
disposition = "attachment; filename=\"test.txt\""
mail(body: attachment_content, content_disposition: disposition)
end
end

Resources