package com.tidemedia.sony;
import java.io.File;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import tidemedia.cms.base.TableUtil;
import tidemedia.cms.system.CmsCache;
public class ImageSendEmail
{
public void SendEmail()
{
}
public static boolean SendEmail(String to_email, int count_up,long size)
throws Exception
{
boolean flag = false;
Properties props = System.getProperties();
props.put("mail.smtp.host", "114.112.56.218");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
InternetAddress[] toList = InternetAddress.parse(to_email, false);
msg.addRecipients(MimeMessage.RecipientType.TO, toList);
InternetAddress fromAddress = new InternetAddress("tidecms@tidemedia.com");
msg.setFrom(fromAddress);
msg.setSentDate(new Date());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String year_now = format.format(date).split("-")[0];
int month_now = date.getMonth() + 1;
int date_now = date.getDate();
msg.setSubject(year_now + "年" + month_now + "月" + date_now + "日 索尼探梦VAIO图片统计情况", "utf-8");
String datetime = format.format(date);
String text = "";
text = text + "索尼探梦VAIO图片统计情况如下:\n";
text = text + "日期:" + datetime + "\n";
text = text + "今日保存图片数量:" + count_up + "\n";
text = text + "今日上传图片总大小:" + size + "M\n";
//text = text + "今日下载数量:" + count_down + "\n";
//System.out.println("TOP21统计情况:"+text);
msg.setText(text, "utf-8");
Transport transport = session.getTransport("smtp");
transport.connect("114.112.56.218", "tidecms@tidemedia.com", "tidecms##0616");
transport.sendMessage(msg, toList);
flag = true;
return flag; }
public static void Reportemail() throws Exception {
String realpath;
String photo_path = CmsCache.getParameterValue("sony_download_image_path");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date currentTime = new Date();
String datetime = formatter.format(currentTime);
TableUtil tu = new TableUtil();
String sql_up = "select count(*) count from (select FROM_UNIXTIME(PublishDate) as PublishDate from channel_s3_k where 1=1) table_up where table_up.PublishDate like '" + datetime + "%'";
ResultSet rs = tu.executeQuery(sql_up);
int count_up = 0;
if (rs.next())
{
count_up = rs.getInt("count");
}
tu.closeRs(rs);
TableUtil tu3 = new TableUtil();
String sql3 = "select Title,Photo from (select Title,Photo,FROM_UNIXTIME(PublishDate) as PublishDate from channel_s3_k where 1=1) table_up where table_up.PublishDate like '" + datetime + "%'";
ResultSet rs3 = tu3.executeQuery(sql3);
long size=0;
while (rs3.next()) {
String filename = rs3.getString("Title");
String filepath=photo_path+"PIC"+datetime.substring(0, 4)+"/"+rs3.getString("Title");
//System.out.println(filepath);
File f = new File(filepath);
if(f.exists()){
size+=f.length();
}else{
System.out.println("文件路径不存在:"+filepath);
}
}
size=size/1024/1024;// 单位M
String paths = CmsCache.getParameterValue("sony_reportImage_email_adress");
int email_num = paths.split(";").length;
String mail_to = "";
for (int i = 0; i < email_num; ++i) {
mail_to = paths.split(";")[i];
try
{
System.out.println("mail_to="+mail_to);
boolean flag = SendEmail(mail_to, count_up,size);
if (flag==false) {
System.out.print("<p style='color:red'>VAIO展图片保存情况邮件发送失败,您的邮箱的用户名或者密码不正确</p><br>");
}
System.out.print("VAIO展图片保存情况邮件发送成功<br>");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------------
package com.tidemedia.sony;
import java.io.PrintStream;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class ImageSendEmailUtil
implements Job
{
public void execute(JobExecutionContext arg0)
throws JobExecutionException
{
try
{
System.out.println("sony开始发送VAIO email...");
ImageSendEmail sendEmail = new ImageSendEmail();
ImageSendEmail.Reportemail();
System.out.println("sony发送完毕VAIO email...");
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}
}
SendEmail java发送邮件
最新推荐文章于 2022-07-16 22:08:26 发布