MailHelp.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.qxgmat.help;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.nuliji.tools.exception.ParameterException;
  4. import com.nuliji.tools.third.sendcloud.SendCloudMail;
  5. import com.nuliji.tools.third.sendcloud.SendCloudSms;
  6. import com.qxgmat.data.constants.SessionKey;
  7. import com.qxgmat.dto.SmsSessionDto;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.core.io.FileSystemResource;
  13. import org.springframework.stereotype.Service;
  14. import javax.servlet.http.HttpSession;
  15. import java.util.Date;
  16. import java.util.Map;
  17. /**
  18. * Created by GaoJie on 2017/11/3.
  19. */
  20. @Service
  21. public class MailHelp {
  22. private static final Logger logger = LoggerFactory.getLogger(MailHelp.class);
  23. private SendCloudMail mail;
  24. @Value("${third.sendcloud.from}")
  25. private String from;
  26. @Value("${third.sendcloud.fromName}")
  27. private String fromName;
  28. @Autowired
  29. private void getSms(@Value("${third.sendcloud.apiUser}") String apiUser,
  30. @Value("${third.sendcloud.apiKey}") String apiKey) {
  31. this.mail = new SendCloudMail(apiUser, apiKey);
  32. }
  33. public boolean sendBaseMail(String email, String subject, String body){
  34. SendCloudMail.Response response = mail.sendMail(email, subject, body, from, fromName, null);
  35. return response.getResult();
  36. }
  37. public boolean sendAttachMail(String email, String subject, String body, String filePath){
  38. SendCloudMail.Response response = mail.sendMail(email, subject, body, from, fromName, new FileSystemResource(filePath));
  39. return response.getResult();
  40. }
  41. }