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

    <legend id='BaXmo'><style id='BaXmo'><dir id='BaXmo'><q id='BaXmo'></q></dir></style></legend>
    <tfoot id='BaXmo'></tfoot>

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

        通过java在特定日期发送自动邮件

        Send automatic mail on specific date through java(通过java在特定日期发送自动邮件)
          <i id='fQazs'><tr id='fQazs'><dt id='fQazs'><q id='fQazs'><span id='fQazs'><b id='fQazs'><form id='fQazs'><ins id='fQazs'></ins><ul id='fQazs'></ul><sub id='fQazs'></sub></form><legend id='fQazs'></legend><bdo id='fQazs'><pre id='fQazs'><center id='fQazs'></center></pre></bdo></b><th id='fQazs'></th></span></q></dt></tr></i><div id='fQazs'><tfoot id='fQazs'></tfoot><dl id='fQazs'><fieldset id='fQazs'></fieldset></dl></div>

            1. <legend id='fQazs'><style id='fQazs'><dir id='fQazs'><q id='fQazs'></q></dir></style></legend><tfoot id='fQazs'></tfoot>
                  <tbody id='fQazs'></tbody>
                • <bdo id='fQazs'></bdo><ul id='fQazs'></ul>

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

                  本文介绍了通过java在特定日期发送自动邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Java 邮件 API 通过我的 Java 应用程序发送电子邮件.但我想在未来日期自动发送它,即每个月/年的任何特定日期.我已经使用我的 ISP 的 SMTP 服务器在提到的 id 上发送电子邮件.我在网上参考了以下可用示例.如何在此处设置任何特定日期.我尝试过 SimpleDateFormat 并将其设置在此处,但它仍会立即发送邮件,但将其发送日期设置为上述特定日期.有没有其他方法可以在提到的日期和时间发送自动电子邮件?

                  I am using Java mail API to send email through my java application. But I want to send it automatically on future date i.e. any specific date of every month/year. I have used my ISP's SMTP server to send email on mentioned id.I have referred the below available example on net. How to set any specific date here.I have tried SimpleDateFormat and set it here but it still sends mail immediately but set its sent date as mentioned specific date. Is there any other way to send automatic email on mentioned date and time?

                  import java.util.*;
                  import javax.mail.*;
                  import javax.mail.internet.*;
                  import javax.activation.*;
                  
                  // Send a simple, single part, text/plain e-mail
                  public class TestEmail {
                  
                  public static void main(String[] args) {
                  
                      // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
                      String to = "abc@abc.com";
                      String from = "abc@abc.com";
                      // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
                      String host = "smtp.yourisp.net";
                  
                      // Create properties, get Session
                      Properties props = new Properties();
                  
                      // If using static Transport.send(),
                      // need to specify which host to send it to
                      props.put("mail.smtp.host", host);
                      // To see what is going on behind the scene
                      props.put("mail.debug", "true");
                      Session session = Session.getInstance(props);
                  
                      try {
                          // Instantiatee a message
                          Message msg = new MimeMessage(session);
                  
                          //Set message attributes
                          msg.setFrom(new InternetAddress(from));
                          InternetAddress[] address = {new InternetAddress(to)};
                          msg.setRecipients(Message.RecipientType.TO, address);
                          msg.setSubject("Test E-Mail through Java");
                          msg.setSentDate(new Date());
                  
                          // Set message content
                          msg.setText("This is a test of sending a " +
                                      "plain text e-mail through Java.
                  " +
                                      "Here is line 2.");
                  
                          //Send the message
                          Transport.send(msg);
                      }
                      catch (MessagingException mex) {
                          // Prints all nested (chained) exceptions as well
                          mex.printStackTrace();
                      }
                  }
                  }//End of class
                  

                  推荐答案

                  如果您使用的是 EJB 3.0+ 容器,则可以轻松使用计时器服务.

                  If you're using an EJB 3.0+ container, you could easily use the timer service.

                  您需要创建一个会话 bean,并实现 TimedObject 接口或使用 @Timeout 注释方法.您可以通过 getTimerService()InitialContext 获取 TimerService 的实例,然后使用 createTimer() 变体.它可能需要一个时间间隔,或者一个 Date 对象指定它何时过期......

                  You need to make a session bean, and either implement the TimedObject interface or annotate a method with @Timeout. You can get an instance of the TimerService from the InitialContext via getTimerService(), then create a timer with one of the createTimer() variants. It can take an interval, or a Date object specifying when it expires...

                  这篇关于通过java在特定日期发送自动邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                  <legend id='TxMaC'><style id='TxMaC'><dir id='TxMaC'><q id='TxMaC'></q></dir></style></legend>
                • <tfoot id='TxMaC'></tfoot>

                      • <bdo id='TxMaC'></bdo><ul id='TxMaC'></ul>

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

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