简体   繁体   English

Java中发送邮件时出错

[英]error while sending mail in java

final int port = 587;
String host = "mail.website.com";  
final String user = "abc@website.com";
final String password = "password";  

String to = "abc@yourmail.com"; 

Properties props = new Properties();  
props.put("mail.smtp.host", host);  
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", port);

Session session = Session.getDefaultInstance(props,  
    new javax.mail.Authenticator() {  
        protected PasswordAuthentication getPasswordAuthentication() {  
            return new PasswordAuthentication(user, password);  
        }  
    });  

try {  
    MimeMessage message = new MimeMessage(session);  
    message.setFrom(new InternetAddress(user));  
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));  
    message.setSubject("demo");  
    message.setText("Hello");  

    Transport.send(message);  

    System.out.println("done");  

} catch (MessagingException e) {
    e.printStackTrace();
} 

Error: 错误:

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: com.sun.mail.util.MailConnectException:无法连接到主机,端口:

Your port seems to be closed, are yuu sure is the right one? 您的端口似乎已关闭,您确定正确的端口是吗? I bould bet 25 or 465 ... 我下注25465 ...

POP3 - port 110
IMAP - port 143
SMTP - port 25
HTTP - port 80
Secure SMTP (SSMTP) - port 465
Secure IMAP (IMAP4-SSL) - port 585
IMAP4 over SSL (IMAPS) - port 993
Secure POP3 (SSL-POP) - port 995 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM