Hi, I have configured Logback SmtpAppender. I am receiving mails properly most of the times but sometimes instead of rendering HTML, the whole HTML source is in the email. I am using gmail. I have attached the discussion mail from logback-user mailing list below.
I will be highly obliged if you could provide some information on how I can resolve this. Thank you. Regards, Saurabh Khanduja. ---------- Forwarded message ---------- From: Saurabh Khanduja <khandujasaur...@gmail.com> Date: Sun, Sep 4, 2016 at 3:58 PM Subject: Re: [logback-user] Email sent by logback is sometimes corrupt To: logback users list <logback-u...@qos.ch> Hi David, I was able to trace the sender code to SMTPAppenderBase:374. Most probably the issue is how Multipart or Transport handles this message. Tried debugging further, but I am seriously new to this. This doesn't looks like configuration issue, but more like how mails should be fomatted. I googled about how to send mail for Multipart emails, and found: http://stackoverflow.com/questions/14744197/best-practices-sending-javamail- mime-multipart-emails-and-gmail http://stackoverflow.com/questions/13299155/how-do-i- send-an-html-email-with-javamail *http://stackoverflow.com/questions/5068827/how-do-i-send-an-html-email <http://stackoverflow.com/questions/5068827/how-do-i-send-an-html-email>* - This clearly says html content should not have head, body tags. *Problem: *I'm on Mac and using gmail. IMO google should not display textual mime part. I will be moving this to developers-mailing list. Thank you. *Code:* String contentType = layout.getContentType(); // This is set to HTMLLayout in my conf. if (ContentTypeUtil.isTextual(contentType)) { // This is true as content type is text/html part.setText(sbuf.toString(), charsetEncoding, ContentTypeUtil.getSubType(contentType)); } else { part.setContent(sbuf.toString(), layout.getContentType()); } Multipart mp = new MimeMultipart(); mp.addBodyPart(part); mimeMsg.setContent(mp); mimeMsg.setSentDate(new Date()); addInfo("About to send out SMTP message \"" + subjectStr + "\" to " + Arrays.toString(toAddressArray)); Transport.send(mimeMsg); Thank you. Regards, Saurabh Khanduja. On Sun, Sep 4, 2016 at 9:34 AM, Saurabh Khanduja <khandujasaur...@gmail.com> wrote: > Thank you David for taking the time to explain this. I really appreciate > it. > > Give me some time to see how I can resolve it. Currently logs in such > mails(multi-part) are very hard to read. I will post my findings back, in > case someone else faces the same issue. > > Thank you. > > Regards, > Saurabh Khanduja. > > On Sun, Sep 4, 2016 at 1:45 AM, David Roussel <nab...@diroussel.xsmail.com > > wrote: > >> Saurabh, >> >> I might be wrong, but my understanding is that all html emails are multi >> part emails. One part should be plain text, for if the reader is using a >> plain text email client, or if they are using a screen reader due to visual >> impairments. The second part is the html content. The strange line you >> are seeing is the delimiter between the two parts. There are standards >> describing how multipart emails work, if you google for them you will find >> them. >> >> Thanks >> >> David >> >> >> On 3 Sep 2016, at 11:45, Saurabh Khanduja <khandujasaur...@gmail.com> >> wrote: >> >> Hi, >> I have configured Logback SmtpAppender. I am receiving mails properly >> but sometimes I end up receiving content as shown below. Seems like some >> string is getting prepended "------=_Part_145_1412302184.1472843545450" >> to mail. >> >> I am using this in my Play framework application 2.2. >> >> Has anyone else faced this issue? If so, is there a way to resolve it. >> >> Thank you in advance. >> >> *Mail content:* >> >> ------=_Part_145_1412302184.1472843545450 >> Content-Type: text/html; charset=UTF-8 >> Content-Transfer-Encoding: 7bit >> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " >> http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >> <html> >> <head> >> <title>Logback Log Messages</title> >> <style type="text/css"> >> table { margin-left: 2em; margin-right: 2em; border-left: 2px solid #AAA; >> } >> TR.even { background: #FFFFFF; } >> TR.odd { background: #EAEAEA; } >> TR.warn TD.Level, TR.error TD.Level, TR.fatal TD.Level {font-weight: >> bold; color: #FF4040 } >> TD { padding-right: 1ex; padding-left: 1ex; border-right: 2px solid #AAA; >> } >> TD.Time, TD.Date { text-align: right; font-family: courier, monospace; >> font-size: smaller; } >> TD.Thread { text-align: left; } >> TD.Level { text-align: right; } >> TD.Logger { text-align: left; } >> TR.header { background: #596ED5; color: #FFF; font-weight: bold; >> font-size: larger; } >> TD.Exception { background: #A2AEE8; font-family: courier, monospace;} >> </style> >> >> </head> >> ...My application error logs >> <body> </body> >> >> Thank you. >> >> Regards, >> Saurabh Khanduja. >> _______________________________________________ >> logback-user mailing list >> logback-u...@qos.ch >> http://mailman.qos.ch/mailman/listinfo/logback-user >> >> >> >> _______________________________________________ >> logback-user mailing list >> logback-u...@qos.ch >> http://mailman.qos.ch/mailman/listinfo/logback-user >> > >
_______________________________________________ logback-dev mailing list logback-dev@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-dev