• <tfoot id='eamqK'></tfoot>

    <small id='eamqK'></small><noframes id='eamqK'>

      <i id='eamqK'><tr id='eamqK'><dt id='eamqK'><q id='eamqK'><span id='eamqK'><b id='eamqK'><form id='eamqK'><ins id='eamqK'></ins><ul id='eamqK'></ul><sub id='eamqK'></sub></form><legend id='eamqK'></legend><bdo id='eamqK'><pre id='eamqK'><center id='eamqK'></center></pre></bdo></b><th id='eamqK'></th></span></q></dt></tr></i><div id='eamqK'><tfoot id='eamqK'></tfoot><dl id='eamqK'><fieldset id='eamqK'></fieldset></dl></div>
      <legend id='eamqK'><style id='eamqK'><dir id='eamqK'><q id='eamqK'></q></dir></style></legend>

        <bdo id='eamqK'></bdo><ul id='eamqK'></ul>

        使用 Javamail API 从 yahoo id 向其他电子邮件 id 发送邮件

        时间:2023-10-14
        • <i id='8txql'><tr id='8txql'><dt id='8txql'><q id='8txql'><span id='8txql'><b id='8txql'><form id='8txql'><ins id='8txql'></ins><ul id='8txql'></ul><sub id='8txql'></sub></form><legend id='8txql'></legend><bdo id='8txql'><pre id='8txql'><center id='8txql'></center></pre></bdo></b><th id='8txql'></th></span></q></dt></tr></i><div id='8txql'><tfoot id='8txql'></tfoot><dl id='8txql'><fieldset id='8txql'></fieldset></dl></div>
        • <small id='8txql'></small><noframes id='8txql'>

          <legend id='8txql'><style id='8txql'><dir id='8txql'><q id='8txql'></q></dir></style></legend>
          • <bdo id='8txql'></bdo><ul id='8txql'></ul>

              <tfoot id='8txql'></tfoot>
                <tbody id='8txql'></tbody>
                • 本文介绍了使用 Javamail API 从 yahoo id 向其他电子邮件 id 发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我无法使用 Java 邮件 API 从我的 yahoo id 发送电子邮件.我尝试了谷歌的不同选项,但失败了.请看看我下面的代码,如果我遗漏了什么,请告诉我.在我看来 Yahoo 不提供免费发送邮件的服务,但我不确定.请提供您对此的看法.

                  I am not able to send email from my yahoo id using Java mail API. I tried different options from Google,but fails. Please have a look my below code and let me know if I am missing something. In my point of view Yahoo does not provide the free service to send mails, but I am not sure. Please provide your thoughts on this.

                  import javax.mail.*;
                  import javax.mail.internet.*;
                  import java.util.Properties;
                  
                  public class MailExample {
                      private static final String SMTP_HOST_NAME = "smtp.mail.yahoo.com";
                      private static final int SMTP_HOST_PORT = 587;//465,587,25
                      private static final String SMTP_AUTH_USER = "dummyrls@yahoo.com";
                      private static final String SMTP_AUTH_PWD  = "my password";
                  
                      public static void main(String[] args) throws Exception{
                         new MailExample().test();
                      }
                  
                      public void test() throws Exception{
                          Properties props = new Properties();
                  
                          props.put("mail.transport.protocol", "smtp");
                          props.put("mail.smtp.host", SMTP_HOST_NAME);
                          props.put("mail.smtp.auth", "true");
                          // props.put("mail.smtps.quitwait", "false");
                  
                          Session mailSession = Session.getDefaultInstance(props);
                          mailSession.setDebug(true);
                          Transport transport = mailSession.getTransport();
                  
                          MimeMessage message = new MimeMessage(mailSession);
                          message.setSubject("Testing SMTP-SSL");
                          message.setContent("This is a test", "text/plain");
                  
                          message.addRecipient(Message.RecipientType.TO,
                               new InternetAddress("rlss@abc.com"));
                  
                          transport.connect
                            (SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);
                  
                          transport.sendMessage(message,
                              message.getRecipients(Message.RecipientType.TO));
                          transport.close();
                      }
                  }
                  

                  上面的代码在 Gmail 上运行良好,但在 Yahoo 上却出现如下错误:

                  The above code works fine for Gmail, but for Yahoo it's giving error like:

                  DEBUG: setDebug: JavaMail version 1.4.1 DEBUG: getProvider() 
                    returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,
                    Sun Microsystems, Inc.,1.4.1] DEBUG SMTP: useEhlo true, 
                    useAuth true 
                  DEBUG SMTP: trying to connect to host "smtp.mail.yahoo.com", port 587, 
                    isSSL false Exception in thread "main" 
                  javax.mail.MessagingException: Could not connect to SMTP 
                    host: smtp.mail.yahoo.com, port: 587;   nested exception is:  
                  java.net.ConnectException: Connection timed out: connect    
                  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)  
                  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)  
                  at javax.mail.Service.connect(Service.java:288)     
                  at com.sample.mailexample.MailExample.test(MailExample.java:313)    
                  at com.sample.mailexample.MailExample.main(MailExample.java:291) Caused by: 
                     java.net.ConnectException: Connection timed out: connect     
                  at java.net.PlainSocketImpl.socketConnect(Native Method)    
                  at java.net.PlainSocketImpl.doConnect(Unknown Source)   
                  at java.net.PlainSocketImpl.connectToAddress(Unknown Source)    
                  at java.net.PlainSocketImpl.connect(Unknown Source)     
                  at java.net.SocksSocketImpl.connect(Unknown Source)     
                  at java.net.Socket.connect(Unknown Source)  
                  at java.net.Socket.connect(Unknown Source)  
                  at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)     
                  at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)    
                  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)  
                  ... 4 more
                  

                  我该如何解决这个问题?

                  How can I solve this?

                  推荐答案

                  试试这个代码

                  public class SendMail {
                  
                      String host, port, emailid,username, password;
                      Properties props = System.getProperties();
                      Session l_session = null;
                  
                      public BSendMail() {
                          host = "smtp.mail.yahoo.com";
                          port = "587";
                          emailid = "a@yahoo.com";
                          username = "a";
                          password = "pwd";
                  
                          emailSettings();
                          createSession();
                          sendMessage("a@yahoo.com", "rahul@gmail.com","Test","test Mail");
                      }
                  
                      public void emailSettings() {
                          props.put("mail.smtp.host", host);
                          props.put("mail.smtp.auth", "true");
                          props.put("mail.debug", "false");
                          props.put("mail.smtp.port", port);
                  //        props.put("mail.smtp.socketFactory.port", port);
                  //        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                  //        props.put("mail.smtp.socketFactory.fallback", "false");
                  
                      }
                  
                      public void createSession() {
                  
                          l_session = Session.getInstance(props,
                                  new javax.mail.Authenticator() {
                                      protected PasswordAuthentication getPasswordAuthentication() {
                                          return new PasswordAuthentication(username, password);
                                      }
                                  });
                  
                          l_session.setDebug(true); // Enable the debug mode
                  
                      }
                  
                      public boolean sendMessage(String emailFromUser, String toEmail, String subject, String msg) {
                          //System.out.println("Inside sendMessage 2 :: >> ");
                          try {
                              //System.out.println("Sending Message *********************************** ");
                              MimeMessage message = new MimeMessage(l_session);
                              emailid = emailFromUser;
                              //System.out.println("mail id in property ============= >>>>>>>>>>>>>> " + emailid);
                              //message.setFrom(new InternetAddress(emailid));
                              message.setFrom(new InternetAddress(this.emailid));
                  
                              message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
                              message.addRecipient(Message.RecipientType.BCC, new InternetAddress(AppConstants.fromEmail));
                              message.setSubject(subject);
                              message.setContent(msg, "text/html");
                  
                              //message.setText(msg);
                              Transport.send(message);
                              System.out.println("Message Sent");
                          } catch (MessagingException mex) {
                              mex.printStackTrace();
                          } catch (Exception e) {
                              e.printStackTrace();
                          }//end catch block
                          return true;
                      }
                  
                  }
                  

                  这篇关于使用 Javamail API 从 yahoo id 向其他电子邮件 id 发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从 Java 发送 SMTP 消息? 下一篇:无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1

                  相关文章

                  <i id='tKhLV'><tr id='tKhLV'><dt id='tKhLV'><q id='tKhLV'><span id='tKhLV'><b id='tKhLV'><form id='tKhLV'><ins id='tKhLV'></ins><ul id='tKhLV'></ul><sub id='tKhLV'></sub></form><legend id='tKhLV'></legend><bdo id='tKhLV'><pre id='tKhLV'><center id='tKhLV'></center></pre></bdo></b><th id='tKhLV'></th></span></q></dt></tr></i><div id='tKhLV'><tfoot id='tKhLV'></tfoot><dl id='tKhLV'><fieldset id='tKhLV'></fieldset></dl></div>

                      <bdo id='tKhLV'></bdo><ul id='tKhLV'></ul>
                    <legend id='tKhLV'><style id='tKhLV'><dir id='tKhLV'><q id='tKhLV'></q></dir></style></legend>
                    1. <small id='tKhLV'></small><noframes id='tKhLV'>

                      <tfoot id='tKhLV'></tfoot>