String from = StringUtils.isBlank(emailMessage.getFrom()) ? fromName : (emailMessage.getFrom() + " (" + fromName + ")"); email.setFrom(configuration.getFrom(), from); email.addTo(emailMessage.getTo(), " "); String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "") + StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
SimpleEmail email = new SimpleEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test message"); email.setMsg("This is a simple test of commons-email"); email.send();
import org.apache.commons.mail.SimpleEmail; ... String[] recipients = {"a@foo.com", "b@foo.com"}; SimpleEmail email = new SimpleEmail(); email.setHostName("mail.myserver.com"); for (int i = 0; i < recipients.length; i++) { email.addTo(recipients[i]); } email.setFrom("me@apache.org", "Me"); email.setSubject("Test message"); email.setMsg("This is a simple test of commons-email"); email.send();
@Override public Email to(String name, String toMail) { SimpleEmail email = new SimpleEmail(); try { email.addTo(toMail, name); } catch (EmailException e) { throw new IllegalArgumentException(e); } return email; }
(3) email.addTo((String) withNotNull()); result = new EmailException();
SimpleEmail email = new SimpleEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("Test message"); email.setMsg("This is a simple test of commons-email"); email.send();
while (it.hasNext()) { String key = (String) it.next(); email.addTo((String) toEmails.get(key), key);
String from = StringUtils.isBlank(emailMessage.getFrom()) ? fromName : (emailMessage.getFrom() + " (" + fromName + ")"); email.setFrom(configuration.getFrom(), from); email.addTo(emailMessage.getTo(), " "); String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "") + StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
public Document processDocument(Document doc) throws DocumentProcessorException { SimpleEmail email = new SimpleEmail(); email.setHostName(hostName); try { email.addTo(to); email.setFrom(from); email.setSubject("Document"); email.setMsg(doc.getPrintRepresentation()); email.send(); } catch (EmailException e) { throw new DocumentProcessorException(e); } return doc; }
/** * Testing if we are able to send a partial email with an invalid address. * * https://issues.apache.org/jira/browse/EMAIL-132 * * @throws Exception the test failed. */ @Test public void testPartialSend() throws Exception { final SimpleEmail email = (SimpleEmail) create(SimpleEmail.class); email.addTo(EmailConfiguration.TEST_TO); email.addTo("nobody@is.invalid"); email.setSubject("TestPartialMail"); email.setMsg("This is a test mail ... :-)"); email.setSendPartial(true); EmailUtils.writeMimeMessage( new File("./target/test-emails/partialmail.eml"), send(email).getMimeMessage()); }
public void sendSimpleEmail(String toEmail, String toName, String subject, String msg, String senderEmail, String senderName, String serverName) throws Exception { SimpleEmail email = new SimpleEmail(); ConfigManager cm = ConfigManager.getInstance(); String hostName = serverName==null ? cm .getConfigValue("cms.smtpServer","mail.sany.com"):serverName; String senderE = senderEmail == null ? cm .getConfigValue("cms.mail_sender") : senderEmail; String senderN = senderName == null ? cm.getConfigValue( "cms.mail_senderName", "sany") : senderName; email.setHostName(hostName); email.addTo(toEmail, toName); email.setFrom(senderE, senderN); email.setSubject(subject); email.setContent(msg,"text/plain; charset=utf-8"); email.send(); // TODO Auto-generated method stub }
email.setSmtpPort(25); email.setAuthentication("da.wei", "da.wei"); email.addTo("da.wei@sany.com", "da.wei"); email.setFrom("da.wei@sany.com", "da.wei"); email.setSubject("Test message");
textEmail.addTo(mailTo);