Reputation: 665
I've been trying to find a site which is updated to the newest version of JavaMail, but whenever I try I get this annoying error (Debug enabled)
Help?
DEBUG: setDebug: JavaMail version 1.4.5
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "pop.mail.yahoo.com", port 110, isSSL false
S: +OK hello from popgate-0.8.0.357900 pop001.mail.ir2.yahoo.com
C: CAPA
S: +OK CAPA list follows
IMPLEMENTATION popgate-0.8.0.357900
XOIP
EXPIRE-NEVER
PIPELINING
RESP-CODES
TOP
UIDL
USER
SASL LOGIN PLAIN
STLS
.
DEBUG POP3: PIPELINING enabled
DEBUG POP3: authentication command trace suppressed
DEBUG POP3: authentication command failed
C: QUIT
S: +OK
javax.mail.AuthenticationFailedException: [AUTH] Access to this service is not permitted.
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at dong.pong.ping.Client.main(Client.java:42)
Code:
String smtpHost = "smtp.mail.yahoo.com";
String popHost = "pop.mail.yahoo.com";
String from = "[email protected]";
String to = "[email protected]";
String username = "classified";
String password = "secret";
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", 587);
// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Store store = session.getStore("pop3");
store.connect(popHost, username, password);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to Yahoo's JavaMail");
// Send message
Transport.send(message);
If any of you have a working code, could you post it? Thanks
Upvotes: 2
Views: 8956
Reputation: 787
Try this one using Spring Framework Mail service. It works for me:
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.mail.yahoo.com");
mailSender.setPort(587);
mailSender.setUsername("username1");
mailSender.setPassword("password");
mailSender.setJavaMailProperties(props);
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(email);
message.setTo(email);
message.setSubject(subject);
message.setText(text);
mailSender.send(message);
Upvotes: 0
Reputation: 718798
According to various websites I've seen, the SMTP port for Yahoo is 465
Actually, now that I look at the stack trace, it looks like the problem is occurring when you attempt to connect to the POP3 store. If you are just trying to send email, I don't know why you would need to connect to POP3 at all.
Upvotes: 0
Reputation: 9813
Do you have premium account?
Or is it a Yahoo problem?
Moved to the appropriate forum, but some versions of yahoo (specifically yahoo.com) do not support POP3 access to mail unless you have signed up for a premium account or have a partner service (like AT&T/Yahoo). When it says "Access is not permitted", that's probably what it means - you don't have a premium account.
[AUTH] Access to this service is not permitted
EDIT: see also Java Mail: Unable to send email via Yahoo for working example.
Upvotes: 2
Reputation: 7111
I have checked this page and it seems that your username must be the full address, so you have to change:
String username = "classified";
To:
String username = "[email protected]";
And the SMTP of yahoo is 465 using TLS/SSL.
props.put("mail.smtp.port", 465);
Upvotes: 0