You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "first (JIRA)" <ji...@apache.org> on 2015/04/29 20:55:06 UTC
[jira] [Updated] (EMAIL-153) Email with ltd test give garbage value
[ https://issues.apache.org/jira/browse/EMAIL-153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
first updated EMAIL-153:
------------------------
Description:
Reporting for the first time.Please let me know if I missed anything.
When I send an email with code :
private JavaMailSender mailSender;
mailSender.send(new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
try{
MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage, true, "UTF-8");
mailMessage.setFrom(from);
mailMessage.setSubject(subject);
mailMessage.setTo(to);
if(cc!=null)
mailMessage.setCc(cc);
if(fileAttachments!=null && !fileAttachments.isEmpty()){
......
mailMessage.addAttachment(fileAttachment.getFileName(), contentsAsResource);
}
if(img!=null && !img.isEmpty())
getBodyWithImg(mailMessage,imgs, body);
}catch(Exception e){
_logger.error("Error in prepare(..)",e);
}
}
private void getBodyWithLogos(MimeMessageHelper mailMessage,List<MyImages> imgs,String body) throws MessagingException {
StringBuffer images = new StringBuffer();
for (final Img im: imgs)
images.append("<img src='cid:"+im.getLogoName()....;
mailMessage.setText(images.toString()+"<br/>"+body, true);
for (final Img im: imgs)
attachInline(logo,mailMessage);
private void attachInline(final Imgs img,MimeMessageHelper mailMessage) throws MessagingException {
AbstractResource contentsAsResource = new ByteArrayResource(Base64.decode(logo.getLogoImg().split(",")[1])){
@Override
public String getFilename(){
return img.getName();
}
};
mailMessage.addInline(img.getName(),contentsAsResource);
}
});
}catch(Exception ex){
_logger.error("Error occured while sending mail. Error : "+ex.getMessage());
}
was:
Reporting for the first time.Please let me know if I missed anything.
When I send an email with code :
private JavaMailSender mailSender;
mailSender.send(new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws MessagingException {
try{
MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage, true, "UTF-8");
mailMessage.setFrom(from);
mailMessage.setSubject(subject);
mailMessage.setTo(to);
if(cc!=null)
mailMessage.setCc(cc);
if(fileAttachments!=null && !fileAttachments.isEmpty()){
for (final CpsFileAttachment fileAttachment : fileAttachments) {
AbstractResource contentsAsResource = new ByteArrayResource(Base64.decode(fileAttachment.getFileData().split(",")[1])){
@Override
public String getFilename(){
return fileAttachment.getFileName();
}
};
mailMessage.addAttachment(fileAttachment.getFileName(), contentsAsResource);
}
}
if(logos!=null && !logos.isEmpty())
getBodyWithLogos(mailMessage,logos, body);
}catch(Exception e){
_logger.error("Error in prepare(..)",e);
}
}
private void getBodyWithLogos(MimeMessageHelper mailMessage,List<CpsLogo> logos,String body) throws MessagingException {
CPSEmailConfigLogoPositionEnum position = logos.get(0).getLogoPosition();
StringBuffer images = new StringBuffer();
switch (position) {
case TOP_RIGHT:
for (final CpsLogo logo : logos)
images.append("<img src='cid:"+logo.getLogoName()+"' alt='"+logo.getLogoName()+"' align='right'>");
mailMessage.setText(images.toString()+"<br/>"+body, true);
for (final CpsLogo logo : logos)
attachInline(logo,mailMessage);
break;
case TOP_LEFT:
for (final CpsLogo logo : logos)
images.append("<img src='cid:"+logo.getLogoName()+"' alt='"+logo.getLogoName()+"' align='left'>");
mailMessage.setText(images.toString()+"<br/>"+body, true);
for (final CpsLogo logo : logos)
attachInline(logo,mailMessage);
break;
case BOTTOM_LEFT:
for (final CpsLogo logo : logos)
images.append("<img src='cid:"+logo.getLogoName()+"' alt='"+logo.getLogoName()+"' align='left'>");
mailMessage.setText(body+"<br/>"+images.toString(), true);
for (final CpsLogo logo : logos)
attachInline(logo,mailMessage);
break;
case BOTTOM_RIGHT:
for (final CpsLogo logo : logos)
images.append("<img src='cid:"+logo.getLogoName()+"' alt='"+logo.getLogoName()+"' align='right'>");
mailMessage.setText(body+"<br/>"+images.toString(), true);
for (final CpsLogo logo : logos)
attachInline(logo,mailMessage);
break;
default:
break;
}
}
private void attachInline(final CpsLogo logo,MimeMessageHelper mailMessage) throws MessagingException {
AbstractResource contentsAsResource = new ByteArrayResource(Base64.decode(logo.getLogoImg().split(",")[1])){
@Override
public String getFilename(){
return logo.getLogoName();
}
};
mailMessage.addInline(logo.getLogoName(),contentsAsResource);
}
});
}catch(Exception ex){
_logger.error("Error occured while sending mail. Error : "+ex.getMessage());
}
> Email with ltd test give garbage value
> --------------------------------------
>
> Key: EMAIL-153
> URL: https://issues.apache.org/jira/browse/EMAIL-153
> Project: Commons Email
> Issue Type: Bug
> Reporter: first
> Priority: Blocker
>
> Reporting for the first time.Please let me know if I missed anything.
> When I send an email with code :
> private JavaMailSender mailSender;
> mailSender.send(new MimeMessagePreparator() {
> @Override
> public void prepare(MimeMessage mimeMessage) throws MessagingException {
> try{
> MimeMessageHelper mailMessage = new MimeMessageHelper(mimeMessage, true, "UTF-8");
> mailMessage.setFrom(from);
> mailMessage.setSubject(subject);
> mailMessage.setTo(to);
> if(cc!=null)
> mailMessage.setCc(cc);
>
> if(fileAttachments!=null && !fileAttachments.isEmpty()){
> ......
> mailMessage.addAttachment(fileAttachment.getFileName(), contentsAsResource);
>
> }
>
> if(img!=null && !img.isEmpty())
> getBodyWithImg(mailMessage,imgs, body);
> }catch(Exception e){
> _logger.error("Error in prepare(..)",e);
> }
> }
>
> private void getBodyWithLogos(MimeMessageHelper mailMessage,List<MyImages> imgs,String body) throws MessagingException {
> StringBuffer images = new StringBuffer();
>
>
> for (final Img im: imgs)
> images.append("<img src='cid:"+im.getLogoName()....;
>
> mailMessage.setText(images.toString()+"<br/>"+body, true);
>
>
> for (final Img im: imgs)
> attachInline(logo,mailMessage);
>
>
>
> private void attachInline(final Imgs img,MimeMessageHelper mailMessage) throws MessagingException {
> AbstractResource contentsAsResource = new ByteArrayResource(Base64.decode(logo.getLogoImg().split(",")[1])){
> @Override
> public String getFilename(){
> return img.getName();
> }
> };
> mailMessage.addInline(img.getName(),contentsAsResource);
> }
>
> });
> }catch(Exception ex){
> _logger.error("Error occured while sending mail. Error : "+ex.getMessage());
> }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)