Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.internet.*;
- import javax.mail.*;
- import java.util.Properties;
- public class Mail {
- public static void main(String[] args) throws MessagingException {
- Properties p = new Properties();
- p.put("mail.smtp.host", "smtp.yandex.ru");
- p.put("mail.smtp.socketFactory.port", 465);
- p.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
- p.put("mail.smtp.auth", "true");
- p.put("mail.smtp.port", 465);
- Session session = Session.getDefaultInstance(p,
- new javax.mail.Authenticator(){
- protected PasswordAuthentication getPasswordAuthentication(){
- return new PasswordAuthentication("notification.netcracker@yandex.ru", "netcrackerproject");
- }
- });
- try{
- MimeMessage mess = new MimeMessage(session);
- mess.setFrom(new InternetAddress("notification.netcracker@yandex.ru"));
- mess.setRecipients(Message.RecipientType.TO, InternetAddress.parse("calomonbkm@gmail.com"));
- mess.setSubject("Test");
- mess.setText("TEST");
- Transport.send(mess);
- System.out.println("Готово!");
- }catch (Exception ex){
- ex.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement