List of usage examples for javax.mail.internet MimeMessage saveChanges
@Override public void saveChanges() throws MessagingException
From source file:com.zimbra.cs.service.mail.SendVerificationCode.java
static void sendVerificationCode(String emailAddr, String code, Mailbox mbox) throws MessagingException, ServiceException { MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(mbox.getAccount())); mm.setRecipient(javax.mail.Message.RecipientType.TO, new JavaMailInternetAddress(emailAddr)); mm.setText(L10nUtil.getMessage(L10nUtil.MsgKey.deviceSendVerificationCodeText, mbox.getAccount().getLocale(), code), MimeConstants.P_CHARSET_UTF8); mm.saveChanges(); MailSender mailSender = mbox.getMailSender(); mailSender.setSaveToSent(false);/* w w w . j av a 2 s . c o m*/ mailSender.sendMimeMessage(null, mbox, mm); }
From source file:jenkins.plugins.mailer.tasks.MimeMessageBuilderTest.java
@Test @Issue("JENKINS-26758") public void test_charset_utf8() throws Exception { MimeMessageBuilder messageBuilder = new MimeMessageBuilder(); messageBuilder.setMimeType("text/html"); messageBuilder.setBody("Synthse"); MimeMessage message = messageBuilder.buildMimeMessage(); message.saveChanges(); StringWriter sw = new StringWriter(); ((MimeMultipart) message.getContent()).getBodyPart(0).writeTo(new WriterOutputStream(sw)); Assert.assertEquals("Content-Type: text/html; charset=UTF-8\n" + "Content-Transfer-Encoding: quoted-printable\n\n" + "Synth=C3=A8se", sw.toString().replaceAll("\r\n?", "\n")); }
From source file:jenkins.plugins.mailer.tasks.MimeMessageBuilderTest.java
@Test @Issue("JENKINS-26758") public void test_charset_iso_8859_1() throws Exception { MimeMessageBuilder messageBuilder = new MimeMessageBuilder(); messageBuilder.setMimeType("text/html"); messageBuilder.setCharset("ISO-8859-1"); messageBuilder.setBody("Synthse"); MimeMessage message = messageBuilder.buildMimeMessage(); message.saveChanges(); StringWriter sw = new StringWriter(); ((MimeMultipart) message.getContent()).getBodyPart(0).writeTo(new WriterOutputStream(sw)); Assert.assertEquals("Content-Type: text/html; charset=ISO-8859-1\n" + "Content-Transfer-Encoding: quoted-printable\n\n" + "Synth=E8se", sw.toString().replaceAll("\r\n?", "\n")); }
From source file:net.duckling.ddl.service.mail.impl.MailServiceImpl.java
private void cheat(MimeMessage mimeMessage, String serverDomain) throws MessagingException { mimeMessage.saveChanges(); mimeMessage.setHeader("User-Agent", "Thunderbird 2.0.0.16 (Windows/20080708)"); String messageid = mimeMessage.getHeader("Message-ID", null); messageid = messageid.replaceAll("\\.JavaMail.*", "@" + serverDomain + ">"); mimeMessage.setHeader("Message-ID", messageid); }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.WsdlPackagingRequestFilter.java
protected String initWsdlRequest(WsdlRequest wsdlRequest, ExtendedPostMethod postMethod, String requestContent) throws Exception { MimeMultipart mp = null;/*from w w w . j av a 2 s.co m*/ StringToStringMap contentIds = new StringToStringMap(); boolean isXOP = wsdlRequest.isMtomEnabled() && wsdlRequest.isForceMtom(); // preprocess only if neccessary if (wsdlRequest.isMtomEnabled() || wsdlRequest.isInlineFilesEnabled() || wsdlRequest.getAttachmentCount() > 0) { try { mp = new MimeMultipart(); MessageXmlObject requestXmlObject = new MessageXmlObject(wsdlRequest.getOperation(), requestContent, true); MessageXmlPart[] requestParts = requestXmlObject.getMessageParts(); for (MessageXmlPart requestPart : requestParts) { if (AttachmentUtils.prepareMessagePart(wsdlRequest, mp, requestPart, contentIds)) isXOP = true; } requestContent = requestXmlObject.getMessageContent(); } catch (Throwable e) { SoapUI.log.warn("Failed to process inline/MTOM attachments; " + e); } } // non-multipart request? if (!isXOP && (mp == null || mp.getCount() == 0) && hasContentAttachmentsOnly(wsdlRequest)) { String encoding = System.getProperty("soapui.request.encoding", StringUtils.unquote(wsdlRequest.getEncoding())); byte[] content = StringUtils.isNullOrEmpty(encoding) ? requestContent.getBytes() : requestContent.getBytes(encoding); postMethod.setRequestEntity(new ByteArrayRequestEntity(content)); } else { // make sure.. if (mp == null) mp = new MimeMultipart(); // init root part initRootPart(wsdlRequest, requestContent, mp, isXOP); // init mimeparts AttachmentUtils.addMimeParts(wsdlRequest, Arrays.asList(wsdlRequest.getAttachments()), mp, contentIds); // create request message MimeMessage message = new MimeMessage(AttachmentUtils.JAVAMAIL_SESSION); message.setContent(mp); message.saveChanges(); WsdlRequestMimeMessageRequestEntity mimeMessageRequestEntity = new WsdlRequestMimeMessageRequestEntity( message, isXOP, wsdlRequest); postMethod.setRequestEntity(mimeMessageRequestEntity); postMethod.setRequestHeader("Content-Type", mimeMessageRequestEntity.getContentType()); postMethod.setRequestHeader("MIME-Version", "1.0"); } return requestContent; }
From source file:mitm.application.djigzo.james.mailets.StripUnsupportedFormats.java
@Override public void serviceMail(Mail mail) { try {/*from ww w. jav a 2 s . c o m*/ MimeMessage filtered = unsupportedFormatStripper.strip(mail.getMessage()); if (filtered != null) { filtered.saveChanges(); /* * A new MimeMessage instance will be created. This makes ure that the * MimeMessage can be written by James (using writeTo()). */ mail.setMessage(new MimeMessage(filtered)); } } catch (MessagingException e) { logger.error("Error stripping unsupported formats.", e); } }
From source file:com.adaptris.mail.MailClientImp.java
/** * Reset the state of the message so that it is no longer marked as seen or deleted. * //from w w w . ja v a2 s .co m * @param msg the Message to reset. * @throws Exception on error. */ @Override public void resetMessage(MimeMessage msg) throws Exception { msg.setFlag(Flags.Flag.SEEN, false); msg.setFlag(Flags.Flag.DELETED, false); msg.saveChanges(); }
From source file:com.aurel.track.util.emailHandling.MailBuilder.java
/** * Makes a HTML message with one recipient * @return/*from ww w.j a va 2 s . c o m*/ * @throws Exception */ public MimeMessage makeHTMLMessage(InternetAddress internetAddressFrom, InternetAddress[] internetAddressesTo, String subject, String htmlBody, List<LabelValueBean> attachments) throws Exception { LOGGER.debug("Constructing the HTML MimeMessage with one recipient"); MimeMessage msg = prepareHTMLMimeMessage(internetAddressFrom, subject, htmlBody, attachments); msg.setRecipients(RecipientType.TO, internetAddressesTo); msg.saveChanges(); return msg; }
From source file:com.aurel.track.util.emailHandling.MailBuilder.java
/** * Makes a plain message for one recipient * @param subject/*www. jav a 2 s .c om*/ * @return * @throws Exception */ public MimeMessage makePlainMessage(InternetAddress internetAddressFrom, InternetAddress[] internetAddressesTo, String subject, String plainBody, List<LabelValueBean> attachments) throws Exception { LOGGER.debug("Constructing the plain MimeMessage with one recipient"); MimeMessage msg = preparePlainMimeMessage(internetAddressFrom, subject, plainBody, attachments); msg.setRecipients(RecipientType.TO, internetAddressesTo); msg.saveChanges(); return msg; }