Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Exceptions when trying to send email via java with the help of java mail api

$
0
0

Here is my code for button click

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String tos=to.getText();
    String froms=from.getText();
    String host="localhost";

    Properties props=System.getProperties();

    props.setProperty("mail.smtp.user", froms);
    props.setProperty("mail.smtp.password", "my password");

    final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
    props.setProperty("mail.smtp.host", "smtp.gmail.com");
    props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
    props.setProperty("mail.smtp.socketFactory.fallback", "false");
    props.setProperty("mail.smtp.port", "465");
    props.setProperty("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true");
    props.put("mail.store.protocol", "pop3");
    props.put("mail.transport.protocol", "smtp");
    Session session= Session.getDefaultInstance(props,new Authenticator(){
                         @Override
                         protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(froms, "my password");
                         }});

    try
    { 
        MimeMessage message=new MimeMessage(session);
        message.setFrom(new InternetAddress(froms));
        InternetAddress ip=new InternetAddress(tos);
        message.addRecipient(Message.RecipientType.TO,ip);
        message.setSentDate(new Date());
        message.setSubject(subject.getText());
        message.setText(messageContent.getText());

        Transport.send(message);

        JOptionPane.showMessageDialog(this, "Message sent successfully");
    }
    catch(HeadlessException | MessagingException e)
    {
        System.err.println(e);
        JOptionPane.showMessageDialog(this, e.getMessage());
    }

}

What i'm doing wrong over here? I,m getting following exception:

javax.mail.AuthenticationFailedException: 534-5.7.14 Please log in via your web browser and 534-5.7.14 e8YTsS3Lo3OMrzelDWpE3wPwGVAmVWNUmJ6cR8pp_PJemAB4AD5dQj_bONLKOyNcYUa4Yz 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 s12sm16623355pfd.165 - gsmtp 534-5.7.14 yfLWbfQo_o4JLhaVezEiFbeuFT_Z9hgAu88JaGLSumvl2zpKRaWGgxbp5lhq1JT5yaNGjP 534-5.7.14 kj9zdQPuu8LqdwuDp7esd15LEKE9Wy8348UDQD3ROy4_ViRsDHAoLeLQMSgRrjgT61hO7o 534-5.7.14 RgEb-xZUMd3rCZ_KRXA_xwUj_kjmY> 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 s12sm16623355pfd.165 - gsmtp


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>