Wysyłanie Maila

0

Witam, mam problem z wysłanie maili.
Kod:

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Properties;

@SuppressWarnings("serial")
public class MailPanel extends JPanel {
	
	JButton send;
	
	public MailPanel() {
		setVisible(true);
		
		send = new sendBtn();
		
		add(send);
		//setLayout(new GridLayout(2, 1));
	}
	
	void send() throws MessagingException {
		final String username = "[email protected]";
        final String password = "haslo";

        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", "587");

        Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
          });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("[email protected]"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("[email protected]"));
            message.setSubject("Testing Subject");
            message.setText("Dear Mail Crawler,"
                + "\n\n No spam to my email, please!");

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
	}
	
	class sendBtn extends JButton implements ActionListener {
	       
		public sendBtn() {
			super("Send");
			addActionListener(this);
		}
			        
		@Override
		public void actionPerformed(ActionEvent e) {
			try {
				new MailPanel().send();
			} catch (MessagingException e1) {
				e1.printStackTrace();
			}
		}
	}
}
0

A jaki problem?

0

Problem rozwiązany, w kodzie wszystko ok, problem po stronie poczty google, blokowała działanie aplikacji. Temat do zamknięcia.

0

a jak to odblokowałeś?

0
Złoty Szczur napisał(a):

a jak to odblokowałeś?

Zapewne w panelu ustawień konta.

1 użytkowników online, w tym zalogowanych: 0, gości: 1