Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```java
- try {
- String to="go372900589@yeah.net";
- String from="wzhonggo@outlook.com";
- Properties props = new Properties();
- // props.put("mail.smtp.socketFactory.port", "587");
- // props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
- // props.put("mail.smtp.socketFactory.fallback", "true");
- props.put("mail.smtp.host", "smtp-mail.outlook.com");
- props.put("mail.smtp.port", "587");
- props.put("mail.smtp.starttls.enable","true");
- props.put("mail.smtp.auth", "true");
- Session session = Session.getDefaultInstance(props,
- new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("wzhonggo@outlook.com","xxxxxxxx");
- }
- });
- // Session emailSession = Session.getDefaultInstance(props, null);
- String msgBody = "Sending email using JavaMail API...";
- Message msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(from, "NoReply"));
- msg.addRecipient(Message.RecipientType.TO,
- new InternetAddress(to, "Mr. Recipient"));
- msg.setSubject("Welcome To Java Mail API");
- msg.setText(msgBody);
- Transport.send(msg);
- System.out.println("Email sent successfully...");
- logger.error("Email sent successfully...");
- } catch (AddressException e) {
- logger.error(e.getMessage());
- } catch (MessagingException e) {
- logger.error(e.getMessage());
- } catch (UnsupportedEncodingException e) {
- logger.error(e.getMessage());
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement