Unable to get html email with text fallback and attachments to display correctly

34 views
Skip to first unread message

Richard Mayes

unread,
Oct 26, 2015, 12:31:53 AM10/26/15
to Ponyrb
Hi,

I'm having real issues trying to get a multipart message working correctly. I want a html email with a fallback text and a text logfile attached.

The Pony code I'm trying to use is as follows:

Pony.mail({
               
:to => EmailSettings::EmailTo,
               
:from => 'nor...@somewhere.com',
               
:subject => 'This is the subject',
               
:html_body => get_email_body(result_data, 'EmailTemplates/HtmlEmailTemplate.erb'),
               
:body => get_email_body(result_data, 'EmailTemplates/TextEmailTemplate.erb'),
               
:attachments => {log_file => File.read("logs/#{log_file}")},
               
:charset => 'UTF-8',
               
:text_part_charset => 'UTF-8',
               
:via => :smtp,
               
:via_options => {
                   
:address => EmailSettings::SmtpServer,
                   
:port => EmailSettings::Port,
                   
:enable_starttls_auto => true,
                   
:user_name => EmailSettings::Username,
                   
:password => EmailSettings::Password,
                   
:authentication => EmailSettings::Authentication, # :plain, :login, :cram_md5, no auth by default
                   
:domain => 'localhost.localdomain' # the HELO domain provided by the client to the server
               
}
           
})



However this just shows the text body in outlook rather than the html body. If I remove the attachment the html body shows fine. If I remove the body text the html shows raw in the email window and attaches both the text logfile and the html.

Can anyone see what I'm doing wrong?

Thanks

Ben Prew

unread,
Oct 26, 2015, 12:38:29 AM10/26/15
to Ponyrb
Richard,

That looks reasonable.  Pony uses the Mail gem under the covers, so that gem handles building the mail message.  You'll probably have better luck opening an issue with them, this looks like it might be similar to your problem: https://github.com/mikel/mail/issues/655

Also, what version of the mail gem and outlook are you using?

Thanks

Richard Mayes

unread,
Oct 28, 2015, 1:21:20 PM10/28/15
to Ponyrb
Thanks Ben, Sorry I didn't think about checking the mail issues. :(

It sounds fairly similar to my issue so trying and work around it by 7zip'ing the log file first before attaching. Only problem is it's only picking up the first 1Kb of the 7z file!! Arrg!! Still fairly new to ruby (C# background) so a little slow on debugging issues atm!

Anyway thanks for your help.

Richard Mayes

unread,
Oct 28, 2015, 1:38:24 PM10/28/15
to Ponyrb
Just worked it out, was using File.read rather than IO.binread! Yay all working now! :)
Reply all
Reply to author
Forward
0 new messages