List of usage examples for javax.mail.internet MimeMessage setText
@Override public void setText(String text) throws MessagingException
From source file:davmail.smtp.TestSmtp.java
public void testSendSimpleMessage() throws IOException, MessagingException, InterruptedException { String body = "Test message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body); sendAndCheckMessage(mimeMessage);/*from www . ja va 2 s . co m*/ }
From source file:davmail.smtp.TestSmtp.java
public void testDotMessage() throws IOException, MessagingException, InterruptedException { String body = "First line\r\n.\r\nSecond line"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body); sendAndCheckMessage(mimeMessage);/*from ww w .j ava 2s . c o m*/ }
From source file:davmail.smtp.TestSmtp.java
public void testSendMessageTwice() throws IOException, MessagingException, InterruptedException { Settings.setProperty("davmail.smtpCheckDuplicates", "true"); String body = "First line\r\n.\r\nSecond line"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body); sendAndCheckMessage(mimeMessage);// w w w . j av a2 s . c om sendAndCheckMessage(mimeMessage); }
From source file:davmail.smtp.TestSmtp.java
public void testBccMessage() throws IOException, MessagingException, InterruptedException { MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("to", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test subject dav"); mimeMessage.setText("Test message"); sendAndCheckMessage(mimeMessage, Settings.getProperty("davmail.bcc")); }
From source file:org.codice.ddf.catalog.ui.query.monitor.email.EmailNotifier.java
private void sendEmailForWorkspace(WorkspaceMetacardImpl workspaceMetacard, Long hitCount, String email) { String emailBody = metacardFormatter.format(bodyTemplate, workspaceMetacard, hitCount); String subject = metacardFormatter.format(subjectTemplate, workspaceMetacard, hitCount); Session session = smtpClient.createSession(); try {//from w ww . j a v a 2 s . com MimeMessage mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress(fromEmail)); mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); mimeMessage.setSubject(subject); mimeMessage.setText(emailBody); LOGGER.trace("Attempting to send email"); smtpClient.send(mimeMessage); } catch (MessagingException e) { LOGGER.warn("unable to send email to {}", email, e); } }
From source file:davmail.smtp.TestSmtp.java
public void testSendPlainTextMessage() throws IOException, MessagingException, InterruptedException { String body = "Test plain text message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", Settings.getProperty("davmail.to")); mimeMessage.setSubject("Test text/plain message"); mimeMessage.setText(body); sendAndCheckMessage(mimeMessage);// w w w . ja v a 2 s. c o m }
From source file:org.opencastproject.kernel.mail.SmtpService.java
/** * Method to send a test message./*from ww w.java 2 s. c o m*/ * * @throws MessagingException * if sending the message failed */ private void sendTestMessage(String recipient) throws MessagingException { MimeMessage message = createMessage(); message.addRecipient(RecipientType.TO, new InternetAddress(recipient)); message.setSubject("Test from Matterhorn"); message.setText("Hello world"); message.saveChanges(); send(message); }
From source file:com.consol.citrus.demo.devoxx.service.MailService.java
/** * Send mail via SMTP connection.//from w w w . jav a 2s.c o m * @param to * @param subject * @param body */ public void sendMail(String to, String subject, String body) { Properties props = new Properties(); props.put("mail.smtp.host", mailServerHost); props.put("mail.smtp.port", mailServerPort); props.put("mail.smtp.auth", true); Authenticator authenticator = new Authenticator() { private PasswordAuthentication pa = new PasswordAuthentication(username, password); @Override public PasswordAuthentication getPasswordAuthentication() { return pa; } }; Session session = Session.getInstance(props, authenticator); session.setDebug(true); MimeMessage message = new MimeMessage(session); try { message.setFrom(new InternetAddress(from)); InternetAddress[] address = { new InternetAddress(to) }; message.setRecipients(Message.RecipientType.TO, address); message.setSubject(subject); message.setSentDate(new Date()); message.setText(body); Transport.send(message); } catch (MessagingException e) { log.error("Failed to send mail!", e); } }
From source file:davmail.smtp.TestSmtp.java
public void testComplexToMessage() throws IOException, MessagingException, InterruptedException { String body = "Test message"; MimeMessage mimeMessage = new MimeMessage((Session) null); mimeMessage.addHeader("To", "nickname <" + Settings.getProperty("davmail.to") + '>'); mimeMessage.setSubject("Test subject"); mimeMessage.setText(body); sendAndCheckMessage(mimeMessage);//w ww. j a v a 2 s .co m }
From source file:ftpclient.FTPManager.java
public boolean sendUserMail(String uploadedFileName) { if (settings != null) { try {//ww w .ja v a 2 s. c om String userEmail = db.getUserEmail(uid); Properties props = System.getProperties(); props.setProperty("mail.smtp.host", settings.getSenderEmailHost()); props.setProperty("mail.smtp.auth", "true"); // props.put("mail.smtp.starttls.enable", "true"); // props.put("mail.smtp.port", "587"); Session s = Session.getDefaultInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(settings.getSenderLogin(), new String(settings.getSenderPassword())); } }); MimeMessage msg = new MimeMessage(s); msg.setFrom(settings.getSenderEmail()); msg.addRecipients(Message.RecipientType.TO, userEmail); msg.setSubject("FTP action"); msg.setText("You have succesfully uploaded file " + uploadedFileName); Transport.send(msg); return true; } catch (MessagingException ex) { Logger.getLogger(FTPManager.class.getName()).log(Level.SEVERE, null, ex); return false; } } else { return false; } }