List of usage examples for javax.mail.internet MimeMessage setText
@Override public void setText(String text) throws MessagingException
From source file:com.zimbra.cs.service.admin.VerifyStoreManager.java
private ParsedMessage getMessage(int size) throws Exception { MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession()); mm.setHeader("From", " Jimmy <jimmy@example.com>"); mm.setHeader("To", " Janis <janis@example.com>"); mm.setHeader("Subject", "Hello"); mm.setHeader("Message-ID", "<sakfuslkdhflskjch@oiwm.example.com>"); mm.setText("nothing to see here\r\n" + RandomStringUtils.random(size)); return new ParsedMessage(mm, false); }
From source file:pt.ist.fenix.api.SupportFormResource.java
private void sendEmail(String from, String subject, String body, SupportBean bean) { Properties props = new Properties(); props.put("mail.smtp.host", Objects .firstNonNull(FenixEduAcademicConfiguration.getConfiguration().getMailSmtpHost(), "localhost")); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); try {//from w w w . ja va2s. c o m message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(CoreConfiguration.getConfiguration().defaultSupportEmailAddress())); message.setSubject(subject); message.setText(body); Multipart multipart = new MimeMultipart(); { BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(body); multipart.addBodyPart(messageBodyPart); } if (!Strings.isNullOrEmpty(bean.attachment)) { BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler( new ByteArrayDataSource(Base64.getDecoder().decode(bean.attachment), bean.mimeType))); messageBodyPart.setFileName(bean.fileName); multipart.addBodyPart(messageBodyPart); } message.setContent(multipart); Transport.send(message); } catch (Exception e) { logger.error("Could not send support email! Original message was: " + body, e); } }
From source file:network.thunder.server.etc.Tools.java
public static void emailException(Exception e, Message m, Channel c, Payment p, Transaction channelTransaction, Transaction t) {// w w w. j ava 2 s . c o m String to = "matsjj@gmail.com"; String from = "exception@thunder.network"; String host = "localhost"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); Session session = Session.getDefaultInstance(properties); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("New Critical Exception thrown.."); String text = ""; text += Tools.stacktraceToString(e); text += "\n"; if (m != null) { text += m; } text += "\n"; if (c != null) { text += c; } text += "\n"; if (p != null) { text += p; } text += "\n"; if (channelTransaction != null) { text += channelTransaction; } text += "\n"; if (t != null) { text += t; } // Now set the actual message message.setText(text); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException mex) { // mex.printStackTrace(); } }
From source file:com.silverpeas.mailinglist.service.notification.AdvancedNotificationHelperTest.java
@Test public void testMultiSendMail() throws Exception { MimeMessage mail = new MimeMessage(notificationHelper.getSession()); InternetAddress theSimpsons = new InternetAddress("thesimpsons@silverpeas.com"); mail.addFrom(new InternetAddress[] { theSimpsons }); mail.setSubject("Simple text Email test"); mail.setText(textEmailContent); List<ExternalUser> externalUsers = new LinkedList<ExternalUser>(); ExternalUser user = new ExternalUser(); user.setComponentId("100"); user.setEmail("bart.simpson@silverpeas.com"); externalUsers.add(user);//from w ww . j ava 2 s . c om user = new ExternalUser(); user.setComponentId("100"); user.setEmail("homer.simpson@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("lisa.simpson@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("marge.simpson@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("maggie.simpson@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("ned.flanders@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("maude.flanders@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("rod.flanders@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("todd.flanders@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("krusty.theklown@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("selma.bouvier@silverpeas.com"); externalUsers.add(user); user = new ExternalUser(); user.setComponentId("100"); user.setEmail("patty.bouvier@silverpeas.com"); externalUsers.add(user); assertThat(externalUsers.size(), is(12)); notificationHelper.sendMail(mail, externalUsers); Iterator<ExternalUser> iter = externalUsers.iterator(); while (iter.hasNext()) { ExternalUser recipient = iter.next(); checkSimpleEmail(recipient.getEmail(), "Simple text Email test"); } }
From source file:edu.washington.iam.tools.IamMailSender.java
private MimeMessage genMimeMessage(IamMailMessage msg) { MimeMessage mime = mailSender.createMimeMessage(); try {/*from w w w . ja va 2 s .c om*/ mime.setRecipients(RecipientType.TO, InternetAddress.parse(msg.getTo())); mime.setSubject(msg.makeSubstitutions(msg.getSubject())); mime.setReplyTo(InternetAddress.parse(replyTo)); mime.setFrom(new InternetAddress(msg.getFrom())); mime.addHeader("X-Auto-Response-Suppress", "NDR, OOF, AutoReply"); mime.addHeader("Precedence", "Special-Delivery, never-bounce"); mime.setText(msg.makeSubstitutions(msg.getText())); } catch (MessagingException e) { log.error("iam mail build fails: " + e); } return mime; }
From source file:com.autentia.tnt.mail.DefaultMailService.java
public void sendOutputStreams(String to, String subject, String text, Map<InputStream, String> attachments) throws MessagingException { Transport t = null;/*from w w w .java 2 s . c o m*/ try { MimeMessage message = new MimeMessage(session); t = session.getTransport("smtp"); message.setFrom(new InternetAddress(configurationUtil.getMailUsername())); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setSentDate(new Date()); if (attachments == null || attachments.size() < 1) { message.setText(text); } else { // create the message part MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(text); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); try { for (InputStream attachment : attachments.keySet()) { messageBodyPart = new MimeBodyPart(); DataSource source = new ByteArrayDataSource(attachment, "application/octet-stream"); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(attachments.get(attachment)); //NOSONAR multipart.addBodyPart(messageBodyPart); //Se emplea keyset y no valueset porque se emplea tanto la key como el val } } catch (IOException e) { throw new MessagingException("cannot add an attachment to mail", e); } message.setContent(multipart); } t.connect(configurationUtil.getMailUsername(), configurationUtil.getMailPassword()); t.sendMessage(message, message.getAllRecipients()); } finally { if (t != null) { t.close(); } } }
From source file:gov.nih.nci.caintegrator.application.mail.SendMail.java
public synchronized void sendMail(String mailTo, String mailCC, String mailBody, String subject) throws ValidationException { try {//from www . j a v a 2 s .com if (mailTo != null && EmailValidator.getInstance().isValid(mailTo)) { //get system properties Properties props = System.getProperties(); String to = mailTo; // Set up mail server props.put("mail.smtp.host", MailConfig.getInstance(mailProperties).getHost()); //Get session Session session = Session.getDefaultInstance(props, null); //Define Message MimeMessage message = new MimeMessage(session); MailManager mailManager = new MailManager(mailProperties); message.setFrom(new InternetAddress(mailManager.formatFromAddress())); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); if ((mailCC != null) && EmailValidator.getInstance().isValid(mailCC)) message.addRecipient(Message.RecipientType.CC, new InternetAddress(mailCC)); message.setSubject(subject); message.setText(mailBody); //Send Message Transport.send(message); } else { throw new ValidationException("Invalid Email Address"); } } catch (Exception e) { logger.error("Send Mail error", e); } //catch }
From source file:org.eclipse.ecr.automation.core.mail.Mailer.java
/** * Send a single email.// www.j ava2 s . co m */ public void sendEmail(String from, String to, String subject, String body) throws MessagingException { // Here, no Authenticator argument is used (it is null). // Authenticators are used to prompt the user for user // name and password. MimeMessage message = new MimeMessage(getSession()); // the "from" address may be set in code, or set in the // config file under "mail.from" ; here, the latter style is used message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setText(body); Transport.send(message); }
From source file:cz.filmtit.userspace.Emailer.java
/** * Sends an email with parameters that has been collected before in the fields of the class. * @return Sign if the email has been successfully sent */// w w w. ja v a 2 s .c om public boolean send() { if (hasCollectedData()) { // send mail; javax.mail.Session session; logger.info("Emailer", "Create session for mail login " + (String) configuration.getProperty("mail.filmtit.address") + " password" + (String) configuration.getProperty("mail.filmtit.password")); session = javax.mail.Session.getDefaultInstance(configuration, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication((String) configuration.getProperty("mail.filmtit.address"), (String) configuration.getProperty("mail.filmtit.password")); } }); session.setDebug(true); javax.mail.internet.MimeMessage message = new javax.mail.internet.MimeMessage(session); try { message.addRecipient(Message.RecipientType.TO, new InternetAddress(this.email)); message.setFrom(new InternetAddress((String) configuration.getProperty("mail.filmtit.address"))); message.setSubject(this.subject); message.setText(this.message); Transport transportSSL = session.getTransport(); transportSSL.connect((String) configuration.getProperty("mail.smtps.host"), Integer.parseInt(configuration.getProperty("mail.smtps.port")), (String) configuration.getProperty("mail.filmtit.address"), (String) configuration.getProperty("mail.filmtit.password")); // account used transportSSL.sendMessage(message, message.getAllRecipients()); transportSSL.close(); } catch (MessagingException ex) { logger.error("Emailer", "An error while sending an email. " + ex); } return true; } logger.warning("Emailer", "Emailer has not collected all data to be able to send an email."); return false; }
From source file:de.helmholtz_muenchen.ibis.utils.abstractNodes.HTExecutorNode.HTExecutorNodeModel.java
private void sendMail(String content) { Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", emailhost); Session session = Session.getDefaultInstance(properties); try {/*w w w . j a va 2 s . c o m*/ MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(emailsender)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); message.setSubject(HEADER); message.setText(content); Transport.send(message); } catch (MessagingException mex) { mex.printStackTrace(); } }