|
@@ -136,64 +136,69 @@ public class MktMailMessageServiceImpl extends MyBaseServiceImpl<MktMailMessageM
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public MktMailMessageEntity send(MktSendMailDTO dto, Long operatorId) {
|
|
public MktMailMessageEntity send(MktSendMailDTO dto, Long operatorId) {
|
|
|
- if (dto == null || dto.getAccountId() == null) {
|
|
|
|
|
- throw new WebException("发信账户不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (CollectionUtils.isEmpty(dto.getRecipientls())) {
|
|
|
|
|
- throw new WebException("收件人不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- dto.setRecipient(dto.getRecipientls().get(0));
|
|
|
|
|
- if (!StringUtils.hasText(dto.getRecipient())) {
|
|
|
|
|
- throw new WebException("收件人不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- if (!StringUtils.hasText(dto.getSubject())) {
|
|
|
|
|
- throw new WebException("主题不能为空");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- SmtpPopSettingsEntity account = mailAccountBizService.requireAccount(dto.getAccountId(), MailSceneEnum.MKT);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (dto == null || dto.getAccountId() == null) {
|
|
|
|
|
+ throw new WebException("发信账户不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollectionUtils.isEmpty(dto.getRecipientls())) {
|
|
|
|
|
+ throw new WebException("收件人不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ dto.setRecipient(dto.getRecipientls().get(0));
|
|
|
|
|
+ if (!StringUtils.hasText(dto.getRecipient())) {
|
|
|
|
|
+ throw new WebException("收件人不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StringUtils.hasText(dto.getSubject())) {
|
|
|
|
|
+ throw new WebException("主题不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- MktMailMessageEntity entity = resolveWritableEntity(dto.getId(), operatorId);
|
|
|
|
|
- fillMessageFields(entity, dto, account, operatorId);
|
|
|
|
|
- ensureTrackToken(entity, dto.getIsTrack());
|
|
|
|
|
- assertTrackReady(entity);
|
|
|
|
|
|
|
+ SmtpPopSettingsEntity account = mailAccountBizService.requireAccount(dto.getAccountId(), MailSceneEnum.MKT);
|
|
|
|
|
+
|
|
|
|
|
+ MktMailMessageEntity entity = resolveWritableEntity(dto.getId(), operatorId);
|
|
|
|
|
+ fillMessageFields(entity, dto, account, operatorId);
|
|
|
|
|
+ ensureTrackToken(entity, dto.getIsTrack());
|
|
|
|
|
+ assertTrackReady(entity);
|
|
|
|
|
+
|
|
|
|
|
+ boolean delayed = dto.getDelaySendTime() != null && dto.getDelaySendTime().after(new Date());
|
|
|
|
|
+ entity.setFolder(MktMailFolderEnum.SENTING.code);
|
|
|
|
|
+ entity.setInOutMark(2);
|
|
|
|
|
+ if (delayed) {
|
|
|
|
|
+ entity.setStatus(STATUS_DELAY);
|
|
|
|
|
+ entity.setDelaySendTime(dto.getDelaySendTime());
|
|
|
|
|
+ this.saveOrUpdate(entity);
|
|
|
|
|
+ mktMailStatusService.ensureStatus(entity);
|
|
|
|
|
+ bindTempAttachments(entity.getId(), dto.getFileIds(), operatorId);
|
|
|
|
|
+ copyFormalToTemp(entity.getId(), dto.getOldFileIds(), operatorId);
|
|
|
|
|
+ return entity;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- boolean delayed = dto.getDelaySendTime() != null && dto.getDelaySendTime().after(new Date());
|
|
|
|
|
- entity.setFolder(MktMailFolderEnum.SENTING.code);
|
|
|
|
|
- entity.setInOutMark(2);
|
|
|
|
|
- if (delayed) {
|
|
|
|
|
- entity.setStatus(STATUS_DELAY);
|
|
|
|
|
- entity.setDelaySendTime(dto.getDelaySendTime());
|
|
|
|
|
|
|
+ entity.setStatus(STATUS_SENDING);
|
|
|
|
|
+ entity.setDelaySendTime(null);
|
|
|
this.saveOrUpdate(entity);
|
|
this.saveOrUpdate(entity);
|
|
|
mktMailStatusService.ensureStatus(entity);
|
|
mktMailStatusService.ensureStatus(entity);
|
|
|
bindTempAttachments(entity.getId(), dto.getFileIds(), operatorId);
|
|
bindTempAttachments(entity.getId(), dto.getFileIds(), operatorId);
|
|
|
|
|
+ // 正式附件拷入临时表,MIME 与成功后转正式统一按 mailId 处理,避免重复挂载
|
|
|
copyFormalToTemp(entity.getId(), dto.getOldFileIds(), operatorId);
|
|
copyFormalToTemp(entity.getId(), dto.getOldFileIds(), operatorId);
|
|
|
- return entity;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- entity.setStatus(STATUS_SENDING);
|
|
|
|
|
- entity.setDelaySendTime(null);
|
|
|
|
|
- this.saveOrUpdate(entity);
|
|
|
|
|
- mktMailStatusService.ensureStatus(entity);
|
|
|
|
|
- bindTempAttachments(entity.getId(), dto.getFileIds(), operatorId);
|
|
|
|
|
- // 正式附件拷入临时表,MIME 与成功后转正式统一按 mailId 处理,避免重复挂载
|
|
|
|
|
- copyFormalToTemp(entity.getId(), dto.getOldFileIds(), operatorId);
|
|
|
|
|
|
|
|
|
|
- SmtpPopSettingsEntity decrypted = decryptAccount(account);
|
|
|
|
|
- boolean async = Boolean.TRUE.equals(dto.getAsync());
|
|
|
|
|
- if (async) {
|
|
|
|
|
- dispatchSmtpSend(entity.getId(), decrypted, true);
|
|
|
|
|
- return entity;
|
|
|
|
|
- }
|
|
|
|
|
- MailSendStatus status = dispatchSmtpSend(entity.getId(), decrypted, false);
|
|
|
|
|
- MktMailMessageEntity latest = this.getById(entity.getId());
|
|
|
|
|
- if (latest != null) {
|
|
|
|
|
- if (status == MailSendStatus.SERVER_LOGIN_FAIL || status == MailSendStatus.FAILED
|
|
|
|
|
- || status == MailSendStatus.SERVER_EXCEPTION_550) {
|
|
|
|
|
- // 状态已由 MktMailSender 回调回写
|
|
|
|
|
|
|
+ SmtpPopSettingsEntity decrypted = decryptAccount(account);
|
|
|
|
|
+ boolean async = Boolean.TRUE.equals(dto.getAsync());
|
|
|
|
|
+ if (async) {
|
|
|
|
|
+ dispatchSmtpSend(entity.getId(), decrypted, true);
|
|
|
|
|
+ return entity;
|
|
|
|
|
+ }
|
|
|
|
|
+ MailSendStatus status = dispatchSmtpSend(entity.getId(), decrypted, false);
|
|
|
|
|
+ MktMailMessageEntity latest = this.getById(entity.getId());
|
|
|
|
|
+ if (latest != null) {
|
|
|
|
|
+ if (status == MailSendStatus.SERVER_LOGIN_FAIL || status == MailSendStatus.FAILED
|
|
|
|
|
+ || status == MailSendStatus.SERVER_EXCEPTION_550) {
|
|
|
|
|
+ // 状态已由 MktMailSender 回调回写
|
|
|
|
|
+ }
|
|
|
|
|
+ return latest;
|
|
|
}
|
|
}
|
|
|
- return latest;
|
|
|
|
|
|
|
+ return entity;
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ log.error("send mail error ----", e);
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- return entity;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|