When I send a message with attachment using the Gmail API, the recipient receives the message without the attachment.
What is strange though is that:
1: in the sent folder of the sender, I do see the attachment properly
2: if I send to myself, both message are fine (in sent folder and in inbox folder)
3: if I use with GMail SMTP with the same raw message, it works fine
4: if I use a 3rd party SMTP with the same raw message, it works fine.
Point number 1+2 super puzzling.
Here is the source of the original message in the sent folder:
Received: from 13936824666 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Jan 2017 18:44:30 -0500
Date: Wed, 25 Jan 2017 18:44:30 -0500
From: Jeremy Chatelaine <source#gmail.com>
To: Jeremy <target#domain.com>
Message-Id: <CABX8Avad0vTtu8=jotRD5HM1r0My-ZKeV7RFRo0TmTxf5PNd0g#mail.gmail.com>
Subject: Export
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="--==_mimepart_5889385be5066_a133fd0f785e20837629"; charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Please find attached the message
----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
Please find attached the message
----==_mimepart_5889385be5066_a133fd0f785e20837629
Content-Type: text/csv; charset=UTF-8; filename=export.csv
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=export.csv
Content-ID: <5889385be6fd7_a133fd0f785e20837735#jeremy.mail>
Some text...
----==_mimepart_5889385be5066_a133fd0f785e20837629--
Here is the source of the original message in the recipient inbox folder:
Delivered-To: target#domain.com
Received: by 10.55.110.193 with SMTP id j184csp1999707qkc;
Wed, 25 Jan 2017 16:30:42 -0800 (PST)
X-Received: by 10.107.34.213 with SMTP id i204mr540101ioi.203.1485390642385;
Wed, 25 Jan 2017 16:30:42 -0800 (PST)
Return-Path: <source#domain.com>
Received: from mail-it0-x22b.google.com (mail-it0-x22b.google.com. [2607:f8b0:4001:c0b::22b])
by mx.google.com with ESMTPS id 88si336719ioq.54.2017.01.25.16.30.42
for <target#domain.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Wed, 25 Jan 2017 16:30:42 -0800 (PST)
Received-SPF: pass (google.com: domain of source#domain.com designates 2607:f8b0:4001:c0b::22b as permitted sender) client-ip=2607:f8b0:4001:c0b::22b;
Authentication-Results: mx.google.com;
dkim=pass header.i=#domain.com;
spf=pass (google.com: domain of source#domain.com designates 2607:f8b0:4001:c0b::22b as permitted sender) smtp.mailfrom=source#domain.com
Received: by mail-it0-x22b.google.com with SMTP id 203so119411500ith.0
for <target#domain.com>; Wed, 25 Jan 2017 16:30:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=domain.com; s=domain;
h=from:mime-version:date:message-id:subject:to;
bh=wx26/V0bJk9VItDp3TAvKl28UAn7IRQq4NITJZDM+Co=;
b=L3KTzPTCoIJUfAacuJy+PE8jHnY9iwGuXUWSpZzneRs5bvMysigSMyPGn1YicyIvQ6
d/LvbEJPlsu+S0zElhIVPITjAmXKDKNIKwLQDHpkcKnnI3btBUrENN923fMtS1fDdHyV
3At0QenKrb34uQqYYoHtX2WU4nyYrISbYKL62=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:mime-version:date:message-id:subject:to;
bh=wx26/V0bJk9VItDp3TAvKl28UAn7IRQq4NITJZDM+Co=;
b=tGPSHjI3iRzjrI0jGHVX76uTw7OXYC4B2bP0qQKgQotBWru+Pn5Ci9A1Qop9oGN1Ys
fnxCgLOLG8ZJU165ODBNX1DGjPa8ud9SWg18FTsxIjNw9qTr1yJqbWr0LToJi7HdQUr8
7Aaiqil7PbPUf5SdxLCqwBNf660Rn9Sd/ADZeT1Bc2+iYQcizjiK/rOPPX+X1ZndvqxP
Ok3Ac2yyIWxi+m4xaPEztcF4JXFZDlJWFdclUDv4s5Jdc0eb1HmB5d2r1qroGLo5MTjd
d7jO1nRsKTO5I9I69p9AgC+LpDiWBxgzZMBVsU6vVpeZ03/pCroyk9DHDUAjn3ijtlFh
O2vw==
X-Gm-Message-State: AIkVDXJo2tPJlkHkthgEjnxYp7vz5Rfpn91pWCS7zEurkSiDhJtyzLpUoSDORq37K/7ATCRSyLAypKIYrdYwEiL2
X-Received: by 10.36.84.148 with SMTP id t142mr20263701ita.90.1485390641934; Wed, 25 Jan 2017 16:30:41 -0800 (PST)
Received: from 13936824667 named unknown by gmailapi.google.com with HTTPREST; Wed, 25 Jan 2017 19:30:41 -0500
From: Jeremy Chatelaine <source#domain.com>
Mime-Version: 1.0
Date: Wed, 25 Jan 2017 19:30:41 -0500
Message-ID: <CABK5xHonVstaJHWHfvBJFF1BK5Y0B8NJsAJTPFokPNAUcawhGA#mail.gmail.com>
Subject: Export
To: Jeremy <target#domain.com>
Content-Type: multipart/alternative; boundary=001a1143a6cc90c9040546f4753f
--001a1143a6cc90c9040546f4753f
Content-Type: text/plain; charset=UTF-8
Please find attached your requested export
--001a1143a6cc90c9040546f4753f
Content-Type: text/html; charset=UTF-8
Please find attached your requested export
--001a1143a6cc90c9040546f4753f--
As you can see, the mime part where I had my text attachment vanished.
Here is how the message is produced (cut for clarity)
msg = Mail.new
html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8'
body html_body
end
msg.html_part = html_part
new_text = plan_text
text_part = Mail::Part.new do
body new_text
end
msg.text_part = text_part
file_paths.each do |file_path|
msg.add_file(file_path)
# I also tried like that, same result
#open(file_path) do |file|
# msg.attachments[file_path] = file.read
#end
end
raw_message = msg.to_s
Here is how I send with the gmail api
client = Google::APIClient.new(:application_name => "app", :application_version => "1")
client.authorization.client_id = "someverylongnumbers.apps.googleusercontent.com"
client.authorization.client_secret = "morerandomletters"
client.authorization.access_token = token
client.authorization.scope = [
"https://www.googleapis.com/auth/gmail.modify"
]
gmail_api = client.discovered_api('gmail', 'v1') # https://www.googleapis.com/auth/gmail.modify
result = client.execute(
:api_method => gmail_api.users.messages.to_h['gmail.users.messages.send'],
:parameters => {
'userId' => "me"
},
:body_object => {
'raw' => Base64.urlsafe_encode64(raw_message)
}
)
What is wrong with this?
According to the documentation, we should be looking at a parameter called "message", which doesn't not come in. What does come in is a parameter called "mandrill_events".
require 'mail'
class InboxController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :create
def create
mail = Mail.new(params[:message])
....
No dice, but I do see this in the console log when I use the following syntax (note, it's so much JSON that SO has trouble viewing it with formatting):
puts JSON.parse(params[:mandrill_events])
{"mandrill_events"=>"[{\"event\":\"inbound\",\"ts\":1426188360,\"msg\":{\"raw_msg\":\"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\\n\\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\\n\\tfor <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\\n for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed\\/relaxed;\\n d=gmail.com; s=20120113;\\n h=mime-version:date:message-id:subject:from:to:content-type;\\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=;\\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6\\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR\\n JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN\\n SAKA==\\nMIME-Version: 1.0\\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\\nDate: Thu, 12 Mar 2015 12:25:59 -0700\\nMessage-ID: <CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\\nSubject: Subject FTW?\\nFrom: Dee diabetic <Deediabetic#gmail.com>\\nTo: test#inbound.diabetesdelivery.com\\nContent-Type: multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/plain; charset=UTF-8\\n\\nBody here\\n\\n--001a113d39288bfe8505111c5a88\\nContent-Type: text\\/html; charset=UTF-8\\n\\n<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n--001a113d39288bfe8505111c5a88--\",\"headers\":{\"Received\":[\"from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\",\"by obcvb8 with SMTP id vb8so16123307obc.10 for <test#inbound.diabetesdelivery.com>; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\"],\"Dkim-Signature\":\"v=1; a=rsa-sha256; c=relaxed\\/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw\\/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK\\/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy\\/EBjdOngcgk4Fsp8u11\\/eeB2xqBPUcrR JYeu\\/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP\\/GexVfQzN SAKA==\",\"Mime-Version\":\"1.0\",\"X-Received\":\"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\",\"Date\":\"Thu, 12 Mar 2015 12:25:59 -0700\",\"Message-Id\":\"<CAMf1_47jvgW6QMwDx8R9JU6C5YiUMaPjvFz3muxhM5v4HJyoSg#mail.gmail.com>\",\"Subject\":\"Subject FTW?\",\"From\":\"Dee diabetic <Deediabetic#gmail.com>\",\"To\":\"test#inbound.diabetesdelivery.com\",\"Content-Type\":\"multipart\\/alternative; boundary=001a113d39288bfe8505111c5a88\"},\"text\":\"Body here\\n\\n\",\"text_flowed\":false,\"html\":\"<div dir=\\\"ltr\\\">Body here<\\/div>\\n\\n\",\"from_email\":\"Deediabetic#gmail.com\",\"from_name\":\"Dee diabetic\",\"to\":[[\"test#inbound.diabetesdelivery.com\",null]],\"subject\":\"Subject FTW?\",\"spf\":{\"result\":\"pass\",\"detail\":\"sender SPF authorized\"},\"spam_report\":{\"score\":0.5,\"matched_rules\":[{\"name\":\"RCVD_IN_DNSWL_LOW\",\"score\":-0.7,\"description\":\"RBL: Sender listed at http:\\/\\/www.dnswl.org\\/, low\"},{\"name\":null,\"score\":0,\"description\":null},{\"name\":\"listed\",\"score\":0,\"description\":\"in list.dnswl.org]\"},{\"name\":\"FREEMAIL_FROM\",\"score\":0,\"description\":\"Sender email is commonly abused enduser mail provider\"},{\"name\":\"HTML_MESSAGE\",\"score\":0,\"description\":\"BODY: HTML included in message\"},{\"name\":\"DKIM_VALID_AU\",\"score\":-0.1,\"description\":\"Message has a valid DKIM or DK signature from author's\"},{\"name\":\"DKIM_SIGNED\",\"score\":0.1,\"description\":\"Message has a DKIM or DK signature, not necessarily valid\"},{\"name\":\"DKIM_VALID\",\"score\":-0.1,\"description\":\"Message has at least one valid DKIM or DK signature\"},{\"name\":\"RDNS_NONE\",\"score\":1.3,\"description\":\"Delivered to internal network by a host with no rDNS\"}]},\"dkim\":{\"signed\":true,\"valid\":true},\"email\":\"test#inbound.diabetesdelivery.com\",\"tags\":[],\"sender\":null,\"template\":null}}]"}
Mar 12 12:26:046666 app/web.1: {"event"=>"inbound", "ts"=>1426188360, "msg"=>{"raw_msg"=>"Received: from mail-ob0-f181.google.com (unknown [209.85.214.181])\n\tby ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509\n\tfor ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)\nReceived: by obcvb8 with SMTP id vb8so16123307obc.10\n for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20120113;\n h=mime-version:date:message-id:subject:from:to:content-type;\n bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=;\n b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6\n LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb\n bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR\n JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i\n ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN\n SAKA==\nMIME-Version: 1.0\nX-Received: by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432;\n Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nReceived: by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)\nDate: Thu, 12 Mar 2015 12:25:59 -0700\nMessage-ID: \nSubject: Subject FTW?\nFrom: Dee diabetic \nTo: test#inbound.diabetesdelivery.com\nContent-Type: multipart/alternative; boundary=001a113d39288bfe8505111c5a88\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/plain; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88\nContent-Type: text/html; charset=UTF-8\n\nBody here\n\n--001a113d39288bfe8505111c5a88--", "headers"=>{"Received"=>["from mail-ob0-f181.google.com (unknown [209.85.214.181]) by ip-10-39-136-77 (Postfix) with ESMTPS id 25B0E2C0509 for ; Thu, 12 Mar 2015 19:26:00 +0000 (UTC)", "by obcvb8 with SMTP id vb8so16123307obc.10 for ; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "by 10.60.119.68 with HTTP; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)"], "Dkim-Signature"=>"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=jyd6a9aMNBrnuDpbsOEokXnACKw/lLnh72zkG7LCs3c=; b=wzt6xiplBtL6dq7uGR8RV6tRR9Lcsmj5zmIktZ7KXFcxbwezN+uEhK/XFw6ZjIfhp6 LVoEH5ljLjOwK4X4nrtHaPoNzHZizwQUzxk0qXGabTXHW6tqOLZUs3FeDwtt2ekeLvlb bDuU4VcBnNZ5VkXDpA5hQeysCfGECBilAtMy/EBjdOngcgk4Fsp8u11/eeB2xqBPUcrR JYeu/99XossdoeJW3avfxFDBw7ngc98oRS2ZPpyL7MY36XoCZCM25U9ue9kBcJ82n92i ctbNdl+9ikVPdcmUokI0WIvBIBGl5yAcrvOQffxmaTz0c31fkq8+iyprDMP/GexVfQzN SAKA==", "Mime-Version"=>"1.0", "X-Received"=>"by 10.202.89.135 with SMTP id n129mr34093639oib.60.1426188359432; Thu, 12 Mar 2015 12:25:59 -0700 (PDT)", "Date"=>"Thu, 12 Mar 2015 12:25:59 -0700", "Message-Id"=>"", "Subject"=>"Subject FTW?", "From"=>"Dee diabetic ", "To"=>"test#inbound.diabetesdelivery.com", "Content-Type"=>"multipart/alternative; boundary=001a113d39288bfe8505111c5a88"}, "text"=>"Body here\n\n", "text_flowed"=>false, "html"=>"Body here\n\n", "from_email"=>"Deediabetic#gmail.com", "from_name"=>"Dee diabetic", "to"=>[["test#inbound.diabetesdelivery.com", nil]], "subject"=>"Subject FTW?", "spf"=>{"result"=>"pass", "detail"=>"sender SPF authorized"}, "spam_report"=>{"score"=>0.5, "matched_rules"=>[{"name"=>"RCVD_IN_DNSWL_LOW", "score"=>-0.7, "description"=>"RBL: Sender listed at http://www.dnswl.org/, low"}, {"name"=>nil, "score"=>0, "description"=>nil}, {"name"=>"listed", "score"=>0, "description"=>"in list.dnswl.org]"}, {"name"=>"FREEMAIL_FROM", "score"=>0, "description"=>"Sender email is commonly abused enduser mail provider"}, {"name"=>"HTML_MESSAGE", "score"=>0, "description"=>"BODY: HTML included in message"}, {"name"=>"DKIM_VALID_AU", "score"=>-0.1, "description"=>"Message has a valid DKIM or DK signature from author's"}, {"name"=>"DKIM_SIGNED", "score"=>0.1, "description"=>"Message has a DKIM or DK signature, not necessarily valid"}, {"name"=>"DKIM_VALID", "score"=>-0.1, "description"=>"Message has at least one valid DKIM or DK signature"}, {"name"=>"RDNS_NONE", "score"=>1.3, "description"=>"Delivered to internal network by a host with no rDNS"}]}, "dkim"=>{"signed"=>true, "valid"=>true}, "email"=>"test#inbound.diabetesdelivery.com", "tags"=>[], "sender"=>nil, "template"=>nil}}
So I am getting a JSON string, but how exactly is the best way to grab the TO, FROM, and SUBJECT?
Update: I just tried the following:
tester = JSON.parse(params[:mandrill_events])
puts tester[:msg][:subject]
#and even this
puts tester["msg"]["subject"]
Did not work. Got an error: **TypeError (no implicit conversion of String into Integer): **
After a day of banging my head, I came up with the solution. By the way, accessing the values directly doesn't work. I had to loop into it.
incomingMail = params[:mandrill_events]
mail_from = "Cannot read From"
mail_originally_to = "Cannot read To"
mail_subject = "No subject"
mail_date = ""
mail_body = "No email body"
if incomingMail != nil
incomingMail = JSON.parse(incomingMail)
incomingMail.each do |item|
mail_from = item["msg"]["from_email"]
mail_originally_to = item["msg"]["headers"]["To"]
mail_subject = item["msg"]["subject"]
mail_date = item["msg"]["headers"]["Date"]
mail_body = item["msg"]["text"]
mail_body_html = item["msg"]["html"]
end
#Confirm
else
puts "Email not sent. Parameter invalid."
end
I have an IMAP mail with a message string that looks like this:
message = #<Mail::Message:70152447148720, Multipart: false, Headers: <Return-Path: <apache#mail.gameseek.co.uk>>, <Received: by 10.86.68.12 with SMTP id q12cs352558fga; Mon, 9 Mar 2009 04:23:05 -0700 (PDT)>, <Received: by 10.210.137.14 with SMTP id k14mr2429643ebd.46.1236597783700; Mon, 09 Mar 2009 04:23:03 -0700 (PDT)>, <Received: from exproxy-2.exserver.dk (exproxy-2.exserver.dk [195.69.129.163]) by mx.google.com with ESMTP id 27si3500694ewy.75.2009.03.09.04.23.03; Mon, 09 Mar 2009 04:23:03 -0700 (PDT)>, <Received: by exproxy-2.exserver.dk (Postfix, from userid 65534) id DF2F6106EF3; Mon, 9 Mar 2009 12:13:26 +0100 (CET)>, <Received: from exsmtp01.exserver.dk (exsmtp01.exserver.dk [195.69.129.177]) by exproxy-2.exserver.dk (Postfix) with ESMTP id C2CEE106ED0 for <support_email.com#exfwd01.scannet.dk>; Mon, 9 Mar 2009 12:13:26 +0100 (CET)>, <Received: from exsmtp02.exserver.dk ([10.10.10.32]) by exsmtp01.exserver.dk with Microsoft SMTPSVC(6.0.3790.1830); Mon, 9 Mar 2009 12:22:19 +0100>, <Received: from front08.exserver.dk ([195.69.129.93]) by exsmtp02.exserver.dk with Microsoft SMTPSVC(6.0.3790.1830); Mon, 9 Mar 2009 12:22:19 +0100>, <Received: from localhost (front08.exserver.dk [127.0.0.1]) by front08.exserver.dk (Postfix) with ESMTP id F1B2BC4028 for <support#email.com>; Mon, 9 Mar 2009 12:46:22 +0100 (CET)>, <Received: from front08.exserver.dk ([127.0.0.1]) by localhost (front08.exserver.dk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mrYGo4G2pt13 for <support#email.com>; Mon, 9 Mar 2009 12:46:16 +0100 (CET)>, <Received: from mail.gameseek.co.uk (78.109.164.42.srvlist.ukfast.net [78.109.164.42]) by front08.exserver.dk (Postfix) with ESMTP id 99022C4021 for <support#email.com>; Mon, 9 Mar 2009 12:46:16 +0100 (CET)>, <Received: by mail.gameseek.co.uk (Postfix, from userid 48) id D321218DD2D; Mon, 9 Mar 2009 11:22:55 +0000 (GMT)>, <Date: Mon, 09 Mar 2009 11:22:55 +0000>, <From: myorder#gameseek.co.uk>, <Reply-To: myorder#gameseek.co.uk>, <To: support#email.com>, <Message-ID: <20090309112255.D321218DD2D#mail.gameseek.co.uk>>, <Subject: Gameseek Order Refunded: Gh68y1235386413>, <Delivered-To: my#email.com>, <Received-SPF: neutral (google.com: 195.69.129.163 is neither permitted nor denied by best guess record for domain of apache#mail.gameseek.co.uk) client-ip=195.69.129.163;>, <Authentication-Results: mx.google.com; spf=neutral (google.com: 195.69.129.163 is neither permitted nor denied by best guess record for domain of apache#mail.gameseek.co.uk) smtp.mail=apache#mail.gameseek.co.uk>, <X-Exserver-To: support_email.com#exfwd01.scannet.dk>, <X-Virus-Scanned: amavisd-new at exserver.dk>, <X-OriginalArrivalTime: 09 Mar 2009 11:22:19.0838 (UTC) FILETIME=[4F6005E0:01C9A0A9]>, <X-ScanNet-Forward: TTL=5>>
I now wish to give it a proper encoding:
unless message.multipart?
charset = message.charset # => "UTF-8"
if charset != nil
body = message.body.decoded.force_encoding(charset).encode("UTF-8") # => "\n\nHello you,\n\nYour order or part of it has been refunded by Gameseek. The refund will be present on the same payment method you used when purchasing. If no other items are due to be posted to you the postage charge will also be refunded.\n\nPlease allow upto four working days for this refund to process.\n\nIf you have not contacted us about this order then it is most likely you are being refunded for an item we cannot currently get hold of.\n\nWe do apologise if this is the case, we would rather refund customers rather than having them wait weeks and weeks for an item.\n\nIf you have contacted us about this order then you will know why you are being refunded.\nMay we apologise if we have not met your requirements on this occassion.\n\nYour Order: Product | Category | Quantity | Cost\n---------------------------------------------------\nDragon Ball Z - Supersonic Warriors 2 | NintendoDS | 1 | \xA326.97\n\n\nFor all order enquires please contact myorder#gameseek.co.uk\n\nThank you for using Gameseek.\n"
end
end
body = body.split(/Sent from my iPhone/)[0]
The last line raises the following error:
invalid byte sequence in UTF-8
Any idea how to fix this?
The text contains the invalid sequence \xA3. This represents a pound sign in Latin-1 (ISO-8859-1).
"\xA3".force_encoding('ISO-8859-1').encode('UTF-8')
#=> "£"
The quick fix is to replace invalid byte sequences in body with String#scrub, but that will remove them:
"\xA326.97".scrub('')
#=> "26.97"
However, to solve the "real" problem you should look earlier in the pipeline. The supplied charset seems to be wrong. Apparently the message is encoded in Latin-1, although the charset suggests something different. Maybe the problem is on the side of the sender.
We are using a Joomla component and all the messages for the "contact this advertiser" web form go directly to spam. We have tested many email accounts and have made every change I can think of. Any assistance would be great.
here is the page where the web form is:
http://www.shopforbiz.com/buy-a-business/ad/restaurants,26/franchise-sub-shop,31
Here is the email header information:
Delivered-To: adammotta#gmail.com
Received: by 10.194.27.195 with SMTP id v3csp56291wjg;
Thu, 7 Aug 2014 06:01:33 -0700 (PDT)
X-Received: by 10.68.113.133 with SMTP id iy5mr17521168pbb.135.1407416493076;
Thu, 07 Aug 2014 06:01:33 -0700 (PDT)
Return-Path: <inquiry#shopforbiz.com>
Received: from see.seekmomentum.com (see.seekmomentum.com. [198.57.217.77])
by mx.google.com with ESMTPS id ym5si3469643pab.6.2014.08.07.06.01.32
for <adammotta#gmail.com>
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Thu, 07 Aug 2014 06:01:32 -0700 (PDT)
Received-SPF: pass (google.com: domain of inquiry#shopforbiz.com designates 198.57.217.77 as permitted sender) client-ip=198.57.217.77;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of inquiry#shopforbiz.com designates 198.57.217.77 as
permitted sender) smtp.mail=inquiry#shopforbiz.com
Received: from localhost ([127.0.0.1]:35995 helo=www.shopforbiz.com)
by see.seekmomentum.com with esmtpa (Exim 4.82)
(envelope-from <inquiry#shopforbiz.com>)
id 1XFNJz-0003RC-Jy
for adammotta#gmail.com; Thu, 07 Aug 2014 09:01:31 -0400
Date: Thu, 7 Aug 2014 09:01:31 -0400
To: adammotta#gmail.com
From: Shop For Biz <inquiry#shopforbiz.com>
Reply-To: inquiry#shopforbiz.com
Subject: New Inquiry from ShopforBiz
Message-ID: <18888aba9485a3ef865449febf2667c2#www.shopforbiz.com>
X-Priority: 3
X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - see.seekmomentum.com
X-AntiAbuse: Original Domain - seekmomentum.com
X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse: Sender Address Domain - shopforbiz.com
X-Get-Message-Sender-Via: see.seekmomentum.com: authenticated_id: inquiry#shopforbiz.com
X-Source:
X-Source-Args:
X-Source-Dir:
From user: adam
User email: adamd#yaho.com
Your advertisement ''Carry Out Chicken, Ribs & Pizza'' enquiry
test
I am trying to send email from my asp.net mvc 3 application with actionmailer mvc
I sent it to my gmail account and veiw the source
Delivered-To: mygmail#gmail.com
Received: by 10.204.10.11 with SMTP id n11cs48097bkn;
Mon, 20 Jun 2011 09:48:33 -0700 (PDT)
Received: by 10.150.209.3 with SMTP id h3mr5801335ybg.353.1308588512444;
Mon, 20 Jun 2011 09:48:32 -0700 (PDT)
Return-Path: <noreply#mysite.com>
Received: from mail.myhostserver.com (mail.myhostserver.com. [ip address here])
by mx.google.com with ESMTP id r38si5731169yba.61.2011.06.20.19.42.41;
Mon, 20 Jun 2011 09:48:32 -0700 (PDT)
Received-SPF: fail (google.com: domain of noreply#myhostserver.com does not designate 216.41.41.125 as permitted sender) client-ip=216.11.21.125;
Authentication-Results: mx.google.com; spf=hardfail (google.com: domain of noreply#myhostserver.com does not designate 216.41.21.125 as permitted sender) smtp.mail=noreply#myhostserver.com
Message-Id: <4dff79e0.2645960a.472d.49efSMTPIN_ADDED#mx.google.com>
Received: from myhostserver (myhostserver.com [216.14.12.122]) by mail.myhostserver.com with SMTP;
Mon, 20 Jun 2011 11:47:29 -0500
MIME-Version: 1.0
From: noreply#myhostserver.com
To: mygmail#gmail.com
Date: 20 Jun 2011 09:47:30 -0700
Subject: Test Email
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
<html>=0D=0A<head>=0D=0A <title></title>=0D=0A <meta http-e=
quiv=3D"Content-Type" content=3D"text/html; charset=3DUTF-8" />=0D=0A=
</head>=0D=0A<body style=3D"font-size: 1em;">=0D=0A <img s=
rc=3D"http://www.my.site.com/Content/Images/si=
telogo.png" alt=3D"My Logo" style=3D"width: 231=
px; height: 63px;" />=0D=0A=0D=0A <div>=0D=0A =0D=0A<h2=
>TestEmail</h2>=0D=0A=0D=0A=0D=0A </div>=0D=0A <div>My Mai=
ler Footer</div>=0D=0A</body>=0D=0A=0D=0A</html>=0D=0A
*note server names, my email address, ip's been changed.
I viewed the same message through thunderbird(so it still the same gmail address) and I got the same looking html with all those funny characters.
Now I sent it to another email address that is setup with exchange and viewed through outlook 2010.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body style="font-size: 1em;">
<img src="http://mysite.com/Content/Images/sitelogo.png" alt="mysite Logo" style="width: 231px; height: 63px;" />
<div>
<h2>TestEmail</h2>
</div>
<div> Mailer Footer</div>
</body>
</html>
Why does it look normal in outlook 2010 but not gmail/thunderbird?
Edit
Here is one from staples
Delivered-To: myemailk#gmail.com
Received: by 14.227.5.217 with SMTP id w57cs20187wes;
Wed, 22 Jun 2011 09:56:05 -0700 (PDT)
Received: by 11.132.41.10 with SMTP id v10mr221945wfv.185.1308761763097;
Wed, 22 Jun 2011 09:56:03 -0700 (PDT)
Return-Path: <bo-bwff20ebg7m4p3au641sjqcgt5vvs6#b.e.staples.ca>
Received: from mta734.e.staples.com (mta734.e.staples.com [38.117.148.114])
by mx.google.com with SMTP id m3si4122907icx.82.2011.06.44.09.50.02;
Wed, 22 Jun 2011 09:56:03 -0700 (PDT)
Received-SPF: pass (google.com: domain of bo-bwff20ebg7m4p3au641sjqcgt5vvs6#b.e.staples.ca designates 38.137.148.134 as permitted sender) client-ip=34.107.118.125;
DomainKey-Status: good (test mode)
Authentication-Results: mx.google.com; spf=pass (google.com: domain of bo-bwff20ebg7m4p3au641sjqcgt5vvs6#b.e.staples.ca designates 38.117.148.122 as permitted sender) smtp.mail=bo-bwff20ebg7m4p3au641sjqcgt5vvs6#b.e.staples.ca; domainkeys=pass (test mode) header.From=staplescanada#e.staples.ca
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
s=200505; d=e.staples.ca;
b=Ea8rCw0vzifMnnDucyEP7U7dnIz1GZ80sb9XKhvzHr3Qa+iIAQjtX0PT+W0HrNTU2hPumPnz1GOC1irFMNvx8eYPeLqJvk1l6BXms4VQVPMsAe/a6RYM50vVbxWOq0msmtMzVx5YhQbMhMl9XqlhR/czwlzJ0GJjbtoMbEHwU0Y=;
h=Date:Message-ID:List-Unsubscribe:From:To:Subject:MIME-Version:Reply-To:Content-type;
Date: Wed, 22 Jun 2011 16:56:24 -0000
Message-ID: <bwff20ebg7m4p3au641sjqcgt5vvs6.14705389806.671#mta734.e.staples.ca>
List-Unsubscribe: <mailto:rm-0bwff20ebg7m4p3au641sjqcgt5vvs6#e.staples.ca>
From: "Staples" <staplescanada#e.staples.ca>
To: myemailk#gmail.com
Subject: Summer Hot Buys!
MIME-Version: 1.0
Reply-To: "Staples" <support-bwff20ebg7m4p3au641sjqcgt5vvs6#e.staples.ca>
Content-type: multipart/alternative; boundary="=bwff20ebg7m4p3au641sjqcgt5vvs6"
--=bwff20ebg7m4p3au641sjqcgt5vvs6
Content-Type: text/plain; charset="iso-8859-1"
Content-transfer-encoding: 8bit
I am not sure why it says text/plain since it is using html.
The funny characters are just the way the e-mail body is encoded to avoid getting mangled in transport, as the content-transfer-encoding header in the envelope specifies. Outlook shows you the decoded message source, but still the source, whereas GMail and Thunderbird give you a "raw" view of the source. In this case, the encoding used is called quoted-printable.