Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package abc;
- import java.util.*;
- import javax.mail.*;
- import javax.mail.internet.*;
- import javax.activation.*;
- public class SendMail {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String to="to@gmail.com";
- String from="from@gmail.com";
- final String username="from";
- final String password="password";
- Properties properties=new Properties();
- properties.put("mail.smtp.host", "smtp.gmail.com");
- properties.put("mail.smtp.auth", "true");
- properties.put("mail.smtp.starttls.enable", "true");
- properties.put("mail.smtp.port", "587");
- Session session=Session.getInstance(properties,
- new javax.mail.Authenticator(){
- protected PasswordAuthentication getPasswordAuthentication(){
- return new PasswordAuthentication(username, password);
- }
- }
- );
- try{
- Message message=new MimeMessage(session);
- message.setFrom(new InternetAddress(from));
- message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
- message.setSubject("Test Mail");
- message.setText("Hey I wrote a java code to send mail. Thanks ");
- Transport.send(message);
- System.out.println("Sent Mail :)");
- }
- catch(MessagingException e){
- e.printStackTrace();
- }
- }
- }
- javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvHc
- 534-5.7.14 gCjfbim5WYCDTQee6sZlZ2d31nncueOizOcz9NieexN5nSlGr0c49lSZ43qc4RQPQvpWLH
- 534-5.7.14 qCUQUecjIR7qxdYJ5R_WgLxkzD9u4Ds3EEG7ceSMyTZg0dpSGJb-zl5C82YDTdLOYTX5Pl
- 534-5.7.14 tmEfWrmktFCdAxUjtDiPNruDLqhPSIZ9dd187tQjBtOw2X8zx7MUcysN9BRawwDmbXT6mJ
- 534-5.7.14 cLn_sJS5UBuqommn0uJK7W1tPZzU> Please log in via your web browser and
- 534-5.7.14 then try again.
- 534-5.7.14 Learn more at
- 534 5.7.14 https://support.google.com/mail/answer/78754 qy7sm48619995pab.34 - gsmtp
- at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
- at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
- at javax.mail.Service.connect(Service.java:313)
- at javax.mail.Service.connect(Service.java:172)
- at javax.mail.Service.connect(Service.java:121)
- at javax.mail.Transport.send0(Transport.java:190)
- at javax.mail.Transport.send(Transport.java:120)
- at abc.SendMail.main(SendMail.java:36)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement