Reputation: 11121
When sending emails with attachments (html files) to gmail the email body is not sent. If I comment out the attachment settings below it went ok. If it happens that the email doesn't have any attachments it went ok.
I tested out that the issues is caused only when the file has the extension of "html". Other files like log, png are ok.
How can I send .html
files in my send mail function correctly?
Update: I added an extract from the received email and the email body is present as the middle mimepart. Search for Content-ID: <[email protected]>
def email_it(body, subject, to, from, attachment_to_send)
$smtp = 'mail.com.au'
$smtp_port = 25
body_with_footer = body +Email_footer
Pony.mail(
:to => to,
:from => from,
:subject => subject,
:body => Nokogiri::HTML(body_with_footer).text,
:html_body => body_with_footer,
:attachments => attachment_to_send,
:via => :smtp,
:via_options => {
:address => $smtp,
:port => $smtp_port,
:enable_starttls_auto => false
}
)
end
Extract from the received email
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_4fdfd77251dac_a0c1a825dc83328";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
QW50wqBydW7CoG5hbWXCoMKgOsKgRWR1bWF0ZV91cGdyYWRlX211bHRpwqAo
ZXhwcmVzcylPdmVyYWxswqByZXN1bHQ6wqBmYWlswqBBbnTCoHJ1bsKgdG9v
azrCoG5vYm9kecKga25vd3PCoDstKcKgUmVzdG9yaW5nwqBmcm9twqAvdmFy
L2xpYi9lZHVtYXRlL2JkcnMvbG9xdWF0L2RhdGFiYXNlcy93ZWVrbHkvTE9R
VUFULjAuZGIyaW5zdDEuTk9ERTAwMDAuQ0FUTjAwMDAuMjAxMjA2MTAwMjMw
MDYuMDAxVGltZXN0YW1wwqBvZsKgYmFja3VwwqBpbWFnZcKgaXM6wqAxMMKg
SnVuwqAyMDEywqAwMjozMERhdGFiYXNlwqBSQVRJT05BTMKgcmVzdG9yZWTC
oHN1Y2Nlc3NmdWxsecKgZnJvbcKgZGF0YWJhc2U6wqBMT1FVQVRyZXN0b3Jl
wqB0b29rOsKgMDowMDozOC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LURldGFpbHPCoGZvcsKgYWxswqBSYXRpb25hbMKgdGVzdMKgc3VpdHMtLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1FZHVtYXRlX3VwZ3JhZGU6wqBs
b2fCoGZpbGXCoG5vdMKgY3JlYXRlZC7CoEVycm9ywqBpbsKgcHJldmlvdXPC
oHRlc3TCoHN1aXTCoChzdG9wT25GYWlsdXJlPSd0cnVlJynCoG9ywqBpbsKg
YW50wqBydW7CoGl0c2VsZi5Qb3dlcmVkIGJ5IEVkdVRlc3RlciBodHRwOi8v
MTAuMC4wLjUw
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <[email protected]>
Ant run name : Edumate_upgrade_multi (express)<BR>Overall result: fail<BR> <BR>Ant run took: nobody knows ;-)<BR> <BR>Restoring from /var/lib/edumate/bdrs/loquat/databases/weekly/LOQUAT.0.db2inst1.NODE0000.CATN0000.20120610023006.001<BR>Timestamp of backup image is: 10 Jun 2012 02:30<BR>Database RATIONAL restored successfully from database: LOQUAT<BR>restore took: 0:00:38<BR><BR><BR>------------------------------<BR>Details for all Rational test suits<BR>------------------------------<BR><BR>Edumate_upgrade: log file not created. Error in previous test suit (stopOnFailure='true') or in ant run itself.<BR><BR><HR><BR>Powered by EduTester http://10.0.0.50
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8;
filename=rational_ft_logframe.html
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=rational_ft_logframe.html
Content-ID: <[email protected]>
<HTML>
<HEAD>
<META HTTP-EQUIV="charset" CONTENT="utf-8">
from pony google group (not my words)
I have a similar but simpler example.
Pony.mail to: '[email protected]',
from: '[email protected]',
subject: 'test attachments',
html_body: '<p>HTML</p>',
body: 'Text',
attachments: { File.basename(a_file_path) => File.read(a_file_path) }
I believe the content-type and the boundaries are not being set properly. With the above code, I will only see the attachment, I will not see the HTML or text bodies, although they are being sent correctly. I can see them if I look at alternatives (Option-Command-] on OSX Mail), and they appear correctly. The content-type is set to multipart/alternative, there is no Content-Disposition. I believe in this case, we are sending the html, plain text, and attachment all as alternatives, rather than 2 alternatives with an attachment, which I believe is mixed, although setting the content-type multipart/mixed doesn't seem to work either: all 3 appear inline with each other.
Upvotes: 3
Views: 1419
Reputation: 666
Put this attachment under via option like this
Pony.mail to: '[email protected]',
from: '[email protected]',
subject: 'test attachments',
html_body: '<p>HTML</p>',
body: 'Text',
:via_options => { :port => '25',
:address => 'smtp.gmail.com',
:enable_starttls_auto => true,
:attachments: { File.basename(a_file_path) => File.read(a_file_path)}
}
Upvotes: -1
Reputation: 11
For me it worked by adding
headers: { "Content-Type" => "multipart/mixed" }
as a parameter to Pony.mail.
Upvotes: 1
Reputation: 11121
My workaround is to rename .htm(l) files to .txt prior to attaching.
Upvotes: 1