From fa821ed684f249a24a0441e359ff81be9bfe63ea Mon Sep 17 00:00:00 2001 From: wushengyeyouya <690574002@qq.com> Date: Sat, 30 Nov 2019 12:48:02 +0800 Subject: [PATCH] initial commit for sendemail. --- sendemail-appjoint/esb-email-support/pom.xml | 127 ----------- .../src/main/assembly/distribution.xml | 202 ------------------ .../sendemail/sender/EsbEmailSender.java | 96 --------- 3 files changed, 425 deletions(-) delete mode 100644 sendemail-appjoint/esb-email-support/pom.xml delete mode 100644 sendemail-appjoint/esb-email-support/src/main/assembly/distribution.xml delete mode 100644 sendemail-appjoint/esb-email-support/src/main/java/com/webank/wedatasphere/dss/appjoint/sendemail/sender/EsbEmailSender.java diff --git a/sendemail-appjoint/esb-email-support/pom.xml b/sendemail-appjoint/esb-email-support/pom.xml deleted file mode 100644 index 0a7adc437a..0000000000 --- a/sendemail-appjoint/esb-email-support/pom.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - dss - com.webank.wedatasphere.dss - 0.5.0 - - 4.0.0 - - dss-sendmail-appjoint-esb-support - - - - com.webank.wedatasphere.dss - dss-sendmail-appjoint-core - ${dss.version} - - - com.webank.wedatasphere.dss - dss-appjoint-core - ${dss.version} - provided - true - - - - - - - - - - - - com.webank.bdp - email-client - 1.0.0 - - - - - - - - - org.apache.maven.plugins - maven-deploy-plugin - - - - net.alchim31.maven - scala-maven-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.maven.plugins - maven-assembly-plugin - 2.3 - false - - - make-assembly - package - - single - - - - src/main/assembly/distribution.xml - - - - - - false - dss-sendemail-appjoint - false - false - - src/main/assembly/distribution.xml - - - - - - - src/main/java - - **/*.xml - - - - src/main/resources - - **/*.properties - **/application.yml - **/bootstrap.yml - **/log4j2.xml - - - - - - - \ No newline at end of file diff --git a/sendemail-appjoint/esb-email-support/src/main/assembly/distribution.xml b/sendemail-appjoint/esb-email-support/src/main/assembly/distribution.xml deleted file mode 100644 index e210a902c0..0000000000 --- a/sendemail-appjoint/esb-email-support/src/main/assembly/distribution.xml +++ /dev/null @@ -1,202 +0,0 @@ - - - - dss-sendemail-appjoint - - zip - - true - sendemail - - - - - - lib - true - true - false - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ${basedir}/src/main/resources - - appjoint.properties - - 0777 - / - unix - - - - ${basedir}/src/main/resources - - * - - 0777 - conf - unix - - - - - diff --git a/sendemail-appjoint/esb-email-support/src/main/java/com/webank/wedatasphere/dss/appjoint/sendemail/sender/EsbEmailSender.java b/sendemail-appjoint/esb-email-support/src/main/java/com/webank/wedatasphere/dss/appjoint/sendemail/sender/EsbEmailSender.java deleted file mode 100644 index 141a40dbd9..0000000000 --- a/sendemail-appjoint/esb-email-support/src/main/java/com/webank/wedatasphere/dss/appjoint/sendemail/sender/EsbEmailSender.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019 WeBank - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package com.webank.wedatasphere.dss.appjoint.sendemail.sender; - -import com.google.common.collect.Lists; -import com.webank.bdp.email.client.EmailClient; -import com.webank.bdp.email.client.domain.*; -import com.webank.wedatasphere.dss.appjoint.sendemail.Attachment; -import com.webank.wedatasphere.dss.appjoint.sendemail.Email; -import com.webank.wedatasphere.dss.appjoint.sendemail.exception.EmailSendFailedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -/** - * Created by shanhuang on 2019/10/12. - */ -/** - * Webank行内的邮件sender - * - **/ - -public class EsbEmailSender extends AbstractEmailSender { - - private static final Logger logger = LoggerFactory.getLogger(EsbEmailSender.class); - - @Override - public void send(Email email) throws EmailSendFailedException { - EsbEmail esbEmail = parseToEsbEmail(email); - logger.info("Begin to send Email(" + email.getSubject() + ")."); - String res = null; - try { - res = EmailClient.sendEmail(esbEmail); - } catch (Throwable e) { - logger.error("Send email failed: ", e); - EmailSendFailedException ex = new EmailSendFailedException(80001, "Send email failed!"); - ex.initCause(e); - throw ex; - } - logger.info("Send Email(" + email.getSubject() + ") succeed: " + res); - } - - private EsbEmail parseToEsbEmail(Email email) { - EsbEmail esbEmail = new EsbEmail(email.getSubject(), Lists.newArrayList(email.getTo()), email.getContent()); - esbEmail.setAttachments(parseToEsbAttachments(email.getAttachments())); - esbEmail.setBodyFormat(BodyFormat.HTML); - esbEmail.setEmailType(EmaiType.NORMAL); - esbEmail.setCarbonCopyList(Lists.newArrayList(email.getCc())); - esbEmail.setBlindCarbonCopyList(Lists.newArrayList(email.getBcc())); - esbEmail.setPriority(Priority.NORMAL); - return esbEmail; - } - - private List parseToEsbAttachments(Attachment[] attachments) { - List esbAttachments = Lists.newArrayList(); - for(Attachment attachment: attachments){ - EmailAttachment imageAttachment = new EsbMailAttachment(attachment.getName(), attachment.getBase64Str(), attachment.getMediaType()); - imageAttachment.setContentId(attachment.getName()); - imageAttachment.setLinkResource(true); - esbAttachments.add(imageAttachment); - } - return esbAttachments; - } - - class EsbMailAttachment extends EmailAttachment { - private String mediaType; - - public EsbMailAttachment(String name, String data, String mediaType) { - super(name, data); - this.mediaType = mediaType; - } - - public String getMediaType() { - return mediaType; - } - - public void setMediaType(String mediaType) { - this.mediaType = mediaType; - } - } -}