import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class Mail { public static void main( String[] args ) { //пример для отправителя с mail.ru final String username = "[почта отправителя]"; final String password = "[пароль]"; Properties props = new Properties(); props.put("mail.smtp.host", "smtp.mail.ru"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "25"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username,password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("[почта отправителя]")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[почта получателя]")); message.setSubject("Subject"); message.setText("TEST!"); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
- Форум тестировщиков
- → Публикации Galina