Skip to content

Commit

Permalink
发送邮件
Browse files Browse the repository at this point in the history
  • Loading branch information
shuaje committed May 7, 2018
1 parent 93c66a6 commit 929d7a0
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 86 deletions.
151 changes: 65 additions & 86 deletions iBase4J-SYS-Facade/src/main/java/org/ibase4j/model/SysEmailConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.ibase4j.model;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;

Expand All @@ -19,88 +17,69 @@
@TableName("sys_email_config")
public class SysEmailConfig extends BaseModel {

/**
* SMTP服务器
*/
@TableField(value="smtp_host")
private String smtpHost;
/**
* SMTP服务器端口
*/
@TableField(value="smtp_port")
private String smtpPort;
/**
* 发送方式
*/
@TableField(value="send_method")
private String sendMethod;
/**
* 名称
*/
@TableField(value="sender_name")
private String senderName;
/**
* 发邮件邮箱账号
*/
@TableField(value="sender_account")
private String senderAccount;
/**
* 发邮件邮箱密码
*/
@TableField(value="sender_password")
private String senderPassword;


public String getSmtpHost() {
return smtpHost;
}

public void setSmtpHost(String smtpHost) {
this.smtpHost = smtpHost;
}

public String getSmtpPort() {
return smtpPort;
}

public void setSmtpPort(String smtpPort) {
this.smtpPort = smtpPort;
}

public String getSendMethod() {
return sendMethod;
}

public void setSendMethod(String sendMethod) {
this.sendMethod = sendMethod;
}

public String getSenderName() {
return senderName;
}

public void setSenderName(String senderName) {
this.senderName = senderName;
}

public String getSenderAccount() {
return senderAccount;
}

public void setSenderAccount(String senderAccount) {
this.senderAccount = senderAccount;
}

public String getSenderPassword() {
return senderPassword;
}

public void setSenderPassword(String senderPassword) {
this.senderPassword = senderPassword;
}

protected Serializable pkVal() {
return getId();
}

/**
* SMTP服务器
*/
@TableField(value="smtp_host")
private String smtpHost;
/**
* 名称
*/
@TableField(value="sender_name")
private String senderName;
/**
* 发邮件邮箱账号
*/
@TableField(value="sender_account")
private String senderAccount;
/**
* 发邮件邮箱密码
*/
@TableField(value="sender_password")
private String senderPassword;
/**
* 发送邮箱鉴权
*/
@TableField(value = "sender_password_auth")
private String senderPasswordAuth;

public String getSmtpHost() {
return smtpHost;
}

public void setSmtpHost(String smtpHost) {
this.smtpHost = smtpHost;
}

public String getSenderName() {
return senderName;
}

public void setSenderName(String senderName) {
this.senderName = senderName;
}

public String getSenderAccount() {
return senderAccount;
}

public void setSenderAccount(String senderAccount) {
this.senderAccount = senderAccount;
}

public String getSenderPassword() {
return senderPassword;
}

public void setSenderPassword(String senderPassword) {
this.senderPassword = senderPassword;
}

public String getSenderPasswordAuth() {
return senderPasswordAuth;
}

public void setSenderPasswordAuth(String senderPasswordAuth) {
this.senderPasswordAuth = senderPasswordAuth;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package org.ibase4j.service.impl;

import java.util.List;

import org.ibase4j.mapper.SysEmailMapper;
import org.ibase4j.model.SysEmail;
import org.ibase4j.model.SysEmailConfig;
import org.ibase4j.service.ISysEmailConfigService;
import org.ibase4j.service.ISysEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.weibo.api.motan.config.springsupport.annotation.MotanService;

import top.ibase4j.core.base.BaseService;
import top.ibase4j.core.support.email.Email;
import top.ibase4j.core.util.DataUtil;
import top.ibase4j.core.util.EmailUtil;
import top.ibase4j.core.util.InstanceUtil;

/**
* @author ShenHuaJie
Expand All @@ -18,5 +28,24 @@
@Service(interfaceClass = ISysEmailService.class)
@MotanService(interfaceClass = ISysEmailService.class)
public class SysEmailServiceImpl extends BaseService<SysEmail, SysEmailMapper> implements ISysEmailService {
@Autowired
private ISysEmailConfigService emailConfigService;

@Transactional
public void sendEmail(SysEmail record) {
Email email = new Email(record.getSender(), record.getEmailTitle(), record.getEmailContent());
List<SysEmailConfig> emailConfigs = emailConfigService.queryList(InstanceUtil.newHashMap());
if (DataUtil.isEmpty(emailConfigs)) {
logger.warn("缺少邮件配置, 使用配置文件默认配置");
} else {
SysEmailConfig emailConfig = emailConfigs.get(0);
email.setHost(emailConfig.getSmtpHost());
email.setName(emailConfig.getSenderName());
email.setFrom(emailConfig.getSenderName() + "," + emailConfig.getSenderAccount());
email.setPassword(emailConfig.getSenderPassword());
email.setKey(emailConfig.getSenderPasswordAuth());
}
EmailUtil.sendEmail(email);
update(record);
}
}

0 comments on commit 929d7a0

Please sign in to comment.