FETCH command IMAP based on headers defined by RFC822 - imap

I have this command come from Thunderbird client email:
6 UID fetch 1 (UID RFC822.SIZE FLAGS BODY.PEEK[HEADER.FIELDS (From To Cc Bcc Subject Date Message-ID Priority X-Priority References Newsgroups In-Reply-To Content-Type Reply-To)])
To respond it, I send the follows statements:
* 1 FETCH (UID 1 RFC822.SIZE 526 BODY[] {526}
* FLAGS (\Seen)
From: "Bob Smith" <bob#bar.com>
To: "John Smith" <john#foo.com>
Cc: "Joe Aaron" <joe#bar.com>
Subject: Sintaxe correta para criação de cabeçalhos de email
Date: 30 Jul 1996 11:54:54 -0000
Message-ID: <OTJMCQtXnqgMaP1rLJi-cD9IvuH+xuVndE-DoWAZB0cbdffqHdw#mail.gmail.com>
Reply-To: <bob#bar.com>
After this, Thunderbird client not send any command, and don't fetch nothing more and messages don't appear in mailbox.
In Thunderbird client the message "download message" start and never dropout
Is the first time that I study IMAP servers and I no have any idea how to proceed in this question.
Thanks;

Did you send the " OK FETCH completed" response? You must do that to signal command completion to the client.
Check the FETCH command section in the IMAP RFC. More specifically page 58 reveals an OK response example.

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.

Why are my automated confirmation / subscription emails getting flagged as spam in gmail?

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

Resources