Hi,
In my java application I need to send mails to different mail addresses. I am using the next piece of code , but for some reason it doesn't work.
enter code here
public class main {
public static void main(String[] args) {
Properties props = new Properties();
props.put("mail.smtp.host", "mail.yahoo.com.");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
Session session = Session.getInstance(props, new MyAuth());
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
InternetAddress[] address = {new InternetAddress("[email protected]")};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("subject ");
msg.setSentDate(new Date());
msg.setText("Message here ");
Transport.send(msg);
}
catch (MessagingException e) {}
} } class MyAuth extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("my username","my password");
}
}
I get the folowing text from debuging it:
.......... [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com.au.", port 25, isSSL false
Could anyone inform me , where I am doing wrong here ?