public class TestMail { public static void main(String... args) throws Exception { // Create mailer. String hostname = "smtp.example.com"; int port = 2525; String username = "nobody"; String password = "idonttellyou"; Mailer mailer = new Mailer(hostname, port, username, password); // Send mail. String from = "john.doe@example.com"; String to = "jane.doe@example.com"; String subject = "Interesting news"; String message = "I've got JavaMail to work!"; mailer.send(from, to, subject, message); } }
public String getEntryAuthor(Run entry) { return Mailer.descriptor().getAdminAddress(); } }
final Email email = new Email(); String host = "smtp.gmail.com"; Integer port = 587; String from = "username"; String pass = "password"; String[] to = {"to@gmail.com"}; email.setFromAddress("", from); email.setSubject("sending in a group"); for( int i=0; i < to.length; i++ ) { email.addRecipient("", to[i], RecipientType.TO); } email.setText("Welcome to JavaMail"); new Mailer(host, port, from, pass).sendMail(email); // you could also still use your mail session instead new Mailer(session).sendMail(email);
public String getEntryAuthor(LogRecord entry) { return Mailer.descriptor().getAdminAddress(); } },req,rsp);
mailer = new Mailer(); // just an example. But you need to initialize your mailer.
public String getEntryAuthor(FeedItem entry) { return Mailer.descriptor().getAdminAddress(); } },
@WebListener public class Config implements ServletContextListener { private ScheduledExecutorService scheduler; @Override public void contextInitialized(ServletContextEvent event) { long secondsUntilNoon = calculateItSomehow(); long secondsPerDay = 60 * 60 * 24; scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new Mailer(), secondsUntilNoon, secondsPerDay, TimeUnit.SECONDS); } @Override public void contextDestroyed(ServletContextEvent event) { scheduler.shutdownNow(); } }
String username = "nobody"; String password = "forgetit"; this.mailer = new Mailer(hostname, port, username, password); this.to = "you@example.com"; mailer.send(email, to, subject, message); request.setAttribute("message", "Mail succesfully sent!"); request.getRequestDispatcher("/WEB-INF/contact.jsp").forward(request, response);
public String getEntryAuthor(Run entry) { return Mailer.descriptor().getAdminAddress(); } }
public void sendMessage(String to, String subject, String content) { final Email email = new Email.Builder() .from(null, from) .to(null, to) .subject(subject) .textHTML(content) .build(); email.signWithDomainKey(new File(properties.getProperty("mail.smtp.dkim.privatekey")), properties.getProperty("mail.smtp.dkim.signingdomain"), properties.getProperty("mail.smtp.dkim.selector")); new Mailer(...).sendMail(email); }
public String getEntryAuthor(LogRecord entry) { return Mailer.descriptor().getAdminAddress(); } },req,rsp);
Email email = new Email(); (...) new Mailer("smtp.gmail.com", 25, "your user", "your password", TransportStrategy.SMTP_TLS).sendMail(email); new Mailer("smtp.gmail.com", 587, "your user", "your password", TransportStrategy.SMTP_TLS).sendMail(email); new Mailer("smtp.gmail.com", 465, "your user", "your password", TransportStrategy.SMTP_SSL).sendMail(email);
public String getEntryAuthor(FeedItem entry) { return Mailer.descriptor().getAdminAddress(); } },
import org.junit.Test; import static org.mockito.Mockito.*; public class MailerTest { @Test public void test() { // create mock objects ApplicationContextFactory factoryMock = mock(ApplicationContextFactory.class); ApplicationContext contextMock = mock(ApplicationContext.class); Courier courierMock = mock(Courier.class); // define behaviour of mocked objects when(factoryMock.create(anyString())).thenReturn(contextMock); when(contextMock.getBean(anyString())).thenReturn(courierMock); // run the production code new Mailer().sendMailHire(new User(), new Job(), factoryMock); // verify, that close has been called verify(contextMock).close(); } }
public String getEntryAuthor(FeedItem entry) { return Mailer.descriptor().getAdminAddress(); } },
@Override public Publisher newInstance(StaplerRequest req, JSONObject formData) { Mailer m = new Mailer(); req.bindParameters(m,"mailer_"); m.dontNotifyEveryUnstableBuild = req.getParameter("mailer_notifyEveryUnstableBuild")==null; if(hudsonUrl==null) { // if Hudson URL is not configured yet, infer some default hudsonUrl = Functions.inferHudsonURL(req); save(); } return m; }
public String getEntryAuthor(Run entry) { return Mailer.descriptor().getAdminAddress(); } }
@Override public Publisher newInstance(StaplerRequest req, JSONObject formData) { Mailer m = new Mailer(); req.bindParameters(m, "mailer_"); m.dontNotifyEveryUnstableBuild = req.getParameter("mailer_notifyEveryUnstableBuild") == null; if (hudsonUrl == null) { // if Hudson URL is not configured yet, infer some default hudsonUrl = Functions.inferHudsonURL(req); save(); } return m; }
public String getEntryAuthor(FeedItem entry) { return Mailer.descriptor().getAdminAddress(); } },
@Override public Publisher newInstance(StaplerRequest req, JSONObject formData) { Mailer m = new Mailer(); req.bindParameters(m,"mailer_"); m.dontNotifyEveryUnstableBuild = req.getParameter("mailer_notifyEveryUnstableBuild")==null; if(hudsonUrl==null) { // if Hudson URL is not configured yet, infer some default hudsonUrl = Functions.inferHudsonURL(req); save(); } return m; }