📄 emailsender.java
字号:
/*
* Created on 2007-5-12
* Last modified on 2007-10-17
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.mail;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.user.FriendService;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.service.user.UserSettingsService;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.club.exception.ClubException;
public class EmailSender {
public static void main(String args[]){
}
public void sendMail(MailEntry mailEntry) throws ClubException{
UserModel tuser = this.getUserService().findById(mailEntry.getTakerUserId());
UserModel suser = this.getUserService().findById(mailEntry.getSenderUserId());
if(Validator.isEmpty(suser)||Validator.isEmpty(tuser)){
throw new ClubException("发送失败,收件人或发件人的身份不能确认!");
}
byte emailFilter = this.getUserSettingsService().getUserSettingsModel(tuser.getUserId()).getEmailFilter();
if(emailFilter==3){
throw new ClubException("发送失败,对方拒绝接收电子邮件!");
}
else if(emailFilter==1){
if(Validator.isEmpty(
this.getFriendService()
.findByMyUserIdAndFriendUserId(
mailEntry.getTakerUserId()
,mailEntry.getSenderUserId()))
)
{
throw new ClubException("发送失败,对方只接收好友的电子邮件!");
}
}
mailEntry.setFrom(suser.getEmailAddress());
mailEntry.setSender(suser.getUserName());
mailEntry.setTo(tuser.getEmailAddress());
mailEntry.setTaker(tuser.getUserName());
EmailUtils.filterMailfooter(mailEntry);
this.getMailService().sendMail(mailEntry);
}
private MailService getMailService() {
return ServiceWrapper.<MailService>getSingletonInstance(ServiceLocator.EMAIL);
}
private UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
private FriendService getFriendService(){
return ServiceWrapper.<FriendService>getSingletonInstance(ServiceLocator.FRIEND);
}
private UserSettingsService getUserSettingsService(){
return ServiceWrapper.<UserSettingsService>getSingletonInstance(ServiceLocator.USERSETTINGS);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -