Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; import java.util.logging.Level; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.swing.JOptionPane; public class send_mail { public static void sendMail() { //Setting up configurations for the email connection to the Google SMTP server using TLS } public static void main(String[] args) { Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "465"); // props.put("mail.smtp.auth", "true"); //Establishing a session with required user details Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("asifuol2011@gmail.com", "asifshehzad"); } }); try { //Creating a Message object to set the email content MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress("asifuol2011@gmail.com")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("asifuol2011@gmail.com")); msg.setSubject("Good"); String message = "<div style=\"color:red;\">BRIDGEYE</div>"; msg.setContent(message , "text/html; charset=utf-8"); Transport.send(msg); // Transport.c System.out.println("Mail has been sent successfully"); } catch (MessagingException mex) { System.out.println("Unable to send an email" + mex); } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement