Could not connect to SMTP host: smtp.qq.com, port: 25;

原文:Could not connect to SMTP host: smtp.qq.com, port: 25;

译文:无法连接到SMTP主机:smtp.qq.com,端口:25;

原因分析:

1.邮件服务器地址

2.邮件服务器端口后

3.账号

4.密码,不一定时登录密码可能时授权码

5.QQ邮箱过程中出现错误,如果程序之前也可以运行成功的话,可以再次生成授权码,有这个原因的。还是不可以的话就请等一会,服务器也需要时间同步。

以上前四步骤存在错误,因为不同类型邮箱而不同,所以只要我们根据各个邮箱的规则去写。


ps:

我这边根据QQ邮箱写了个demo,地址:点击打开链接




如果还有其他原因,欢迎补充。

发布了145 篇原创文章 · 获赞 128 · 访问量 73万+
展开阅读全文

为什么会提示Could not connect to SMTP host

09-25

public class Mail { public static void main(String[] args) throws Exception { //public static void sendMail(String toEmail) throws Exception{ Properties properties=new Properties(); properties.setProperty("mail.transport.protocol","smtp");//连接时的协议 properties.setProperty("mail.smtp.host","smtp.qq.com");//主机名 properties.setProperty("mail.smtp.port","465");//主机名和端口 properties.setProperty("mail.smtp.auth","true");//是否开启权限控制 properties.setProperty("mail.smtp.ssl.enable","true");//开启ssl安全认证 properties.setProperty("mail.debug","true");//如果设置为true则在发送邮件时会打印发送时的消息 //创建程序到邮件服务器之间的一次会话,即家到邮局的路 Session session=Session.getInstance(properties); //session.setDebug(true);//调试 //获取邮件对象 Message message=new MimeMessage(session);//获取信封 message.setFrom(new InternetAddress("346103239@qq.com"));//发信人 message.setRecipients(MimeMessage.RecipientType.TO,new InternetAddress[]{new InternetAddress("346103239@qq.com")});//收信人,第二个参数是数组,因为收信人可以多个 message.setSubject("这是一封来自Java程序的测试邮件");//标题 message.setText("这是邮件的正文");//正文 //找到邮递员 Transport transport=session.getTransport();//创建快递员对象 transport.connect("346103239@qq.com","我的密码");//告诉邮递员你的用户名密码,证明你是用户 transport.sendMessage(message,message.getAllRecipients());//把信交给快递员,并告诉他收件人地址 transport.close(); } } ``` ``` qq邮箱设置没问题。请问为什么会有错误? Could not connect to SMTP host: smtp.qq.com, port: 465 问答

Spring Mail用QQ邮箱测试发送邮件失败【连接超时】

05-07

求大神解答 Java代码: ``` public class SendMailController { //@Autowired private JavaMailSenderImpl mailSender; @RequestMapping(value ="/sendMail", method = RequestMethod.GET) public void sendMail(HttpServletRequest request) throws MessagingException { mailSender = new JavaMailSenderImpl(); mailSender.setHost("smtp.qq.com"); //设置邮件服务器 mailSender.setUsername("XXXX@qq.com"); mailSender.setPassword("**********"); MimeMessage msg = mailSender.createMimeMessage(); MimeMessageHelper msgHelper = new MimeMessageHelper(msg, true, "utf-8"); msgHelper.setTo("YYYYYYYYY@qq.com"); msgHelper.setFrom("XXXXXXX@qq.com"); msgHelper.setSubject("测试发送带附件的邮件"); msgHelper.setText("测试邮件"); FileSystemResource file = new FileSystemResource(new File("D:/test.png")); msgHelper.addAttachment("test.png", file); //添加附件 Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); prop.put("mail.smtp.timeout", "25000"); mailSender.setJavaMailProperties(prop); mailSender.send(msg); System.out.println("邮件发送成功!"); } } ``` 错误: type Exception report message Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.com, 25; timeout -1; description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.com, 25; timeout -1; nested exception is: java.net.ConnectException: Connection timed out: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.com, 25; timeout -1; nested exception is: java.net.ConnectException: Connection timed out: connect; message exceptions (1) are: Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.qq.com, 25; timeout -1; nested exception is: java.net.ConnectException: Connection timed out: connect org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) javax.servlet.http.HttpServlet.service(HttpServlet.java:620) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 问答

Couldn't connect to host链接超时

06-29

/** * PraseMimeMessage类测试 * @param args * @throws Exception */ public static void main(String args[])throws Exception{ // String host="主机名/ip"; //【pop.mail.yahoo.com.cn】 // String username="用户名"; //【wwp_1124】 // String password="密码"; //【........】 String host="smtp.gmail.com"; //【pop.mail.yahoo.com.cn】 String username="刚注册的163邮箱"; //【wwp_1124】 String password="163邮箱密码"; Properties props=new Properties(); props.put("port", "110"); props.setProperty("mail.smtp.connectiontimeout", "80000"); Session session = Session.getDefaultInstance(props,null); Store store=session.getStore("pop3"); store.connect(host,username,password); Folder folder=store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message message[]=folder.getMessages(); System.out.println("Messages's length: "+message.length); PraseMimeMessage pmm=null; for(int i=0;i<message.length;i++){ pmm=new PraseMimeMessage((MimeMessage)message[i]); System.out.println("Message "+i+" subject: "+pmm.getSubject()); System.out.println("Message "+i+" sentdate: "+pmm.getSentDate()); System.out.println("Message "+i+" replysign: "+pmm.getReplySign()); System.out.println("Message "+i+" hasRead: "+pmm.isNew()); System.out.println("Message "+i+"  containAttachment: "+pmm.isContainAttach((Part)message[i])); System.out.println("Message "+i+" form: "+pmm.getFrom()); System.out.println("Message "+i+" to: "+pmm.getMailAddress("to")); System.out.println("Message "+i+" cc: "+pmm.getMailAddress("cc")); System.out.println("Message "+i+" bcc: "+pmm.getMailAddress("bcc")); pmm.setDateFormat("yy年MM月dd日 HH:mm"); System.out.println("Message "+i+" sentdate: "+pmm.getSentDate()); System.out.println("Message "+i+" Message-ID: "+pmm.getMessageId()); pmm.getMailContent((Part)message[i]); System.out.println("Message "+i+" bodycontent: \r\n"+pmm.getBodyText()); pmm.setAttachPath("c:\\tmp\\coffeecat1124"); pmm.saveAttachMent((Part)message[i]); } 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览