commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "first (JIRA)" <j...@apache.org>
Subject [jira] [Created] (EMAIL-153) Email with ltd test give garbage value
Date Wed, 29 Apr 2015 18:50:07 GMT
first created EMAIL-153:
---------------------------

             Summary: 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()){
								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());
		}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message