Reputation: 4400
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.
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 , what I am doing wrong here ?
Upvotes: 0
Views: 2794
Reputation: 41
Yahoo! Mail SMTP server address: smtp.mail.yahoo.com
Yahoo! Mail SMTP user name: Your full Yahoo! Mail email address (including "@yahoo.com")
Yahoo! Mail SMTP password: Your Yahoo! Mail password
Yahoo! Mail SMTP port: 465
Yahoo! Mail SMTP TLS/SSL required: yes
Similar settings work with gmail. For yahoo you might need yahoo plus account
Upvotes: 2
Reputation: 706
I am not sure, but I faced the same problem when sending mail using a gmail id, you are using yahoo. The problem was gmail uses ssl layer protection, i think same is the case with yahoo so you need to use
mail.smtps.host instead of mail.smtp.host
and same for other properties too.
and isSSL to true.
I can post complete code snippet, once i reach office and use office's machine. For now you can look at http://www.rgagnon.com/javadetails/java-0570.html
Upvotes: 1
Reputation: 23493
It could be an issue with your ISP blocking port 25 traffic (not unusual!)
From http://help.yahoo.com/l/us/yahoo/smallbusiness/bizmail/pop/pop-32.html:
In an attempt to control unsolicited email (spam), some Internet service providers now block port 25, which means you could experience technical problems when sending email. If you are having trouble sending email, you may need to use port 465 (recommended) or 587 when sending email via Yahoo!'s SMTP server.
Upvotes: 0