javaMail 定时发送邮件 javajavamail定时发送 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void start_publish_scheduling(){ Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new MyTask(), date); } static class MyTask extends java.util.TimerTask { @Override public void run() { System.out.println("----execute------"); } } schedule()不是应该还有第三个参数的吗? schedule()不是应该还有第三个参数的吗?可以直接传一个日期。 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。我自己写了一个带参数的sendmail()函数,是要run()里调用这个函数吗? 可是run()不能带参数啊。public class SendMail extends TimerTask{ public void sendMail(String info, String mailAddress, String remindTime) { String month = remindTime.substring(0, remindTime.indexOf("/")); String day = remindTime.substring(remindTime.indexOf("/")+1, remindTime.lastIndexOf("/")); String hour = remindTime.substring(remindTime.lastIndexOf(" ")+1, remindTime.indexOf(":")); String minute = remindTime.substring(remindTime.indexOf(":")+1, remindTime.lastIndexOf("")); int m = Integer.parseInt(month) - 1; int d = Integer.parseInt(day); int h = Integer.parseInt(hour); int mi = Integer.parseInt(minute); Date date = new Date(); date.setMonth(m); date.setDate(d); date.setHours(h); date.setMinutes(mi); Properties props = new Properties(); props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.setProperty("mail.smtp.socketFactory.fallback", "false"); props.setProperty("mail.smtp.port", "465"); props.setProperty("mail.smtp.socketFactory.port", "465"); Session session = Session.getDefaultInstance(props, null); Message msg = new MimeMessage(session); Transport transport = null; System.out.println("从网页传回的时间格式:"+remindTime); String taskdate = ""; try { String msgBody = "您好:" + "\n\n" + taskdate + "\n\n您有日程安排:" + info; msg.setSubject("日程 - 温馨提醒"); msg.setText(msgBody); transport = session.getTransport("smtp"); transport.connect("smtp.gmail.com", "", ""); msg.setRecipient(Message.RecipientType.TO, new InternetAddress( mailAddress)); msg.setSentDate(date); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); } catch (MessagingException e) { e.printStackTrace(); } } @Override public void run() { } schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法run()方法里应该写些什么,我需要用servlet接收网页传回的内容作为邮件的内容。 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗? schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法我理解是这样的,按您写的,run()方法应该写在SendMail类里,在run()方法里应该调用发送邮件的方法sendMail()我的问题就是我通过servlet接收网页请求的数据,在servle里调用sendMail方法,怎么传给run()方法呢。 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 你的需求不需要用的timer schedule啊,只需要前台网页传时间和内容到后台,把你在后台接受到的值传到你的SendMail()方法里不就行了么。 我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。 我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。你把前台的时间保存到数据库,把所有时间放到系统内存,再监听所有时间发送邮件。 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次 schedule()不是应该还有第三个参数的吗?可以直接传一个日期。public static void main(String[] args) { Timer timer = new Timer(); Calendar calendar = Calendar.getInstance(); calendar.set(2014, 04, 9, 17, 16, 00); Date date = calendar.getTime(); timer.schedule(new SendMail(), date);}执行这个main方法会再2014.05.09 17:16:00调用你的run方法这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次能发给我看看,借鉴一下吗? 如何统计并显示... 有兴趣的朋友看过来:一个企业网站的活儿(jsp) 各位大侠请留步,帮个忙。刚学JSP。找了个源码。。。。 也问一个有关applet不显示的问题 请问怎么获取一个字符的ascll码值,又怎么将ascll码转换为原字符! 求教Session相关的Taglib 你见过这么难的吗?送高分 请问如果在jsp中实现报警功能! 54sunboy舍我其谁,请进 求救!android中文乱码!已经三四周了还没解决!!! 关于头信息与详细信息的处理 微信支付接口。做过的大牛戳进来。
public static void start_publish_scheduling(){
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new MyTask(), date);
}
static class MyTask extends java.util.TimerTask { @Override
public void run() {
System.out.println("----execute------");
}
}
schedule()不是应该还有第三个参数的吗?
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。我自己写了一个带参数的sendmail()函数,是要run()里调用这个函数吗? 可是run()不能带参数啊。public class SendMail extends TimerTask{ public void sendMail(String info, String mailAddress,
String remindTime) {
String month = remindTime.substring(0, remindTime.indexOf("/"));
String day = remindTime.substring(remindTime.indexOf("/")+1, remindTime.lastIndexOf("/"));
String hour = remindTime.substring(remindTime.lastIndexOf(" ")+1, remindTime.indexOf(":"));
String minute = remindTime.substring(remindTime.indexOf(":")+1, remindTime.lastIndexOf(""));
int m = Integer.parseInt(month) - 1;
int d = Integer.parseInt(day);
int h = Integer.parseInt(hour);
int mi = Integer.parseInt(minute);
Date date = new Date();
date.setMonth(m);
date.setDate(d);
date.setHours(h);
date.setMinutes(mi); Properties props = new Properties();
props.setProperty("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465"); Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session); Transport transport = null;
System.out.println("从网页传回的时间格式:"+remindTime);
String taskdate = ""; try {
String msgBody = "您好:" + "\n\n" + taskdate + "\n\n您有日程安排:" + info;
msg.setSubject("日程 - 温馨提醒"); msg.setText(msgBody); transport = session.getTransport("smtp");
transport.connect("smtp.gmail.com", "",
""); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(
mailAddress));
msg.setSentDate(date); transport.sendMessage(msg, msg.getAllRecipients()); transport.close();
} catch (MessagingException e) {
e.printStackTrace();
}
} @Override
public void run() {
}
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
run()方法里应该写些什么,我需要用servlet接收网页传回的内容作为邮件的内容。
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
我理解是这样的,按您写的,run()方法应该写在SendMail类里,在run()方法里应该调用发送邮件的方法sendMail()我的问题就是我通过servlet接收网页请求的数据,在servle里调用sendMail方法,怎么传给run()方法呢。
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。
只需要前台网页传时间和内容到后台,把你在后台接受到的值传到你的SendMail()方法里不就行了么。
我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。
我的意思是通过timer把前台传来的时间传入schedule。比如说前台数据是16:00为提醒时间,那么我希望是在系统时间为16:00时发送提醒邮件。而通过message.setSentDate()方法设置的发送时间只是在邮件主题下面显示,邮件仍然是立即就发送出去了,而不是16:00才发送的。
你把前台的时间保存到数据库,把所有时间放到系统内存,再监听所有时间发送邮件。
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次
schedule()不是应该还有第三个参数的吗?
可以直接传一个日期。
public static void main(String[] args) {
Timer timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(2014, 04, 9, 17, 16, 00);
Date date = calendar.getTime();
timer.schedule(new SendMail(), date);
}
执行这个main方法会再2014.05.09 17:16:00调用你的run方法
这里是不可能用servlet去接受网页传过来的信息的,你一定要用servlet吗?
我做的是日程管理网站,希望做一个定时发送给用户发送提醒邮件的功能,只能从网页接收传过来的提醒时间和日程内容啊。 以前做过一次能发给我看看,借鉴一下吗?