-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default email sender is not working #10404
- Loading branch information
1 parent
6dc87f3
commit 14b7f0e
Showing
14 changed files
with
1,038 additions
and
253 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
modules/core/core-api/src/main/java/com/enonic/xp/mail/MailAttachment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.io.ByteSource; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
|
||
@PublicApi | ||
public final class MailAttachment | ||
{ | ||
private final String fileName; | ||
|
||
private final ByteSource data; | ||
|
||
private final String mimeType; | ||
|
||
private final Map<String, String> headers; | ||
|
||
private MailAttachment( final Builder builder ) | ||
{ | ||
this.fileName = Objects.requireNonNull( builder.fileName ); | ||
this.data = Objects.requireNonNull( builder.data ); | ||
this.mimeType = builder.mimeType; | ||
this.headers = builder.headers != null ? ImmutableMap.copyOf( builder.headers ) : ImmutableMap.of(); | ||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public String getFileName() | ||
{ | ||
return fileName; | ||
} | ||
|
||
public ByteSource getData() | ||
{ | ||
return data; | ||
} | ||
|
||
public String getMimeType() | ||
{ | ||
return mimeType; | ||
} | ||
|
||
public Map<String, String> getHeaders() | ||
{ | ||
return headers; | ||
} | ||
|
||
public static class Builder | ||
{ | ||
private String fileName; | ||
|
||
private ByteSource data; | ||
|
||
private String mimeType; | ||
|
||
private Map<String, String> headers; | ||
|
||
public Builder fileName( final String fileName ) | ||
{ | ||
this.fileName = fileName; | ||
return this; | ||
} | ||
|
||
public Builder data( final ByteSource data ) | ||
{ | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
public Builder mimeType( final String mimeType ) | ||
{ | ||
this.mimeType = mimeType; | ||
return this; | ||
} | ||
|
||
public Builder headers( final Map<String, String> headers ) | ||
{ | ||
this.headers = headers; | ||
return this; | ||
} | ||
|
||
public MailAttachment build() | ||
{ | ||
return new MailAttachment( this ); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
modules/core/core-api/src/main/java/com/enonic/xp/mail/MailHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
|
||
@PublicApi | ||
public final class MailHeader | ||
{ | ||
private final String key; | ||
|
||
private final String value; | ||
|
||
public MailHeader( final String key, final String value ) | ||
{ | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public static MailHeader from( final String key, final String value ) | ||
{ | ||
return new MailHeader( key, value ); | ||
} | ||
|
||
public String getKey() | ||
{ | ||
return key; | ||
} | ||
|
||
public String getValue() | ||
{ | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
modules/core/core-api/src/main/java/com/enonic/xp/mail/MailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
|
||
@PublicApi | ||
public interface MailService | ||
{ | ||
@Deprecated | ||
void send( MailMessage message ); | ||
|
||
void send( SendMailParams message ); | ||
} |
230 changes: 230 additions & 0 deletions
230
modules/core/core-api/src/main/java/com/enonic/xp/mail/SendMailParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
package com.enonic.xp.mail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.enonic.xp.annotation.PublicApi; | ||
|
||
@PublicApi | ||
public final class SendMailParams | ||
{ | ||
private final List<String> to; | ||
|
||
private final List<String> from; | ||
|
||
private final List<String> cc; | ||
|
||
private final List<String> bcc; | ||
|
||
private final List<String> replyTo; | ||
|
||
private final List<MailHeader> headers; | ||
|
||
private final List<MailAttachment> attachments; | ||
|
||
private final String subject; | ||
|
||
private final String contentType; | ||
|
||
private final String body; | ||
|
||
private SendMailParams( Builder builder ) | ||
{ | ||
this.to = List.copyOf( builder.to ); | ||
this.from = List.copyOf( builder.from ); | ||
this.cc = List.copyOf( builder.cc ); | ||
this.bcc = List.copyOf( builder.bcc ); | ||
this.replyTo = List.copyOf( builder.replyTo ); | ||
this.headers = List.copyOf( builder.headers ); | ||
this.attachments = List.copyOf( builder.attachments ); | ||
this.subject = builder.subject; | ||
this.contentType = builder.contentType; | ||
this.body = builder.body; | ||
} | ||
|
||
public static Builder create() | ||
{ | ||
return new Builder(); | ||
} | ||
|
||
public List<String> getTo() | ||
{ | ||
return to; | ||
} | ||
|
||
public List<String> getFrom() | ||
{ | ||
return from; | ||
} | ||
|
||
public List<String> getCc() | ||
{ | ||
return cc; | ||
} | ||
|
||
public List<String> getBcc() | ||
{ | ||
return bcc; | ||
} | ||
|
||
public List<String> getReplyTo() | ||
{ | ||
return replyTo; | ||
} | ||
|
||
public String getSubject() | ||
{ | ||
return subject; | ||
} | ||
|
||
public String getContentType() | ||
{ | ||
return contentType; | ||
} | ||
|
||
public String getBody() | ||
{ | ||
return body; | ||
} | ||
|
||
public List<MailHeader> getHeaders() | ||
{ | ||
return headers; | ||
} | ||
|
||
public List<MailAttachment> getAttachments() | ||
{ | ||
return attachments; | ||
} | ||
|
||
public static class Builder | ||
{ | ||
private final List<String> to = new ArrayList<>(); | ||
|
||
private final List<String> from = new ArrayList<>(); | ||
|
||
private final List<String> cc = new ArrayList<>(); | ||
|
||
private final List<String> bcc = new ArrayList<>(); | ||
|
||
private final List<String> replyTo = new ArrayList<>(); | ||
|
||
private final List<MailHeader> headers = new ArrayList<>(); | ||
|
||
private final List<MailAttachment> attachments = new ArrayList<>(); | ||
|
||
private String subject; | ||
|
||
private String contentType; | ||
|
||
private String body; | ||
|
||
public Builder to( final String... to ) | ||
{ | ||
this.to.addAll( List.of( to ) ); | ||
return this; | ||
} | ||
|
||
public Builder to( final Collection<String> to ) | ||
{ | ||
this.to.addAll( to ); | ||
return this; | ||
} | ||
|
||
public Builder from( final String... from ) | ||
{ | ||
this.from.addAll( List.of( from ) ); | ||
return this; | ||
} | ||
|
||
public Builder from( final Collection<String> from ) | ||
{ | ||
this.from.addAll( from ); | ||
return this; | ||
} | ||
|
||
public Builder cc( final String... cc ) | ||
{ | ||
this.cc.addAll( List.of( cc ) ); | ||
return this; | ||
} | ||
|
||
public Builder cc( final Collection<String> cc ) | ||
{ | ||
this.cc.addAll( cc ); | ||
return this; | ||
} | ||
|
||
public Builder bcc( final String... bcc ) | ||
{ | ||
this.bcc.addAll( List.of( bcc ) ); | ||
return this; | ||
} | ||
|
||
public Builder bcc( final Collection<String> bcc ) | ||
{ | ||
this.bcc.addAll( bcc ); | ||
return this; | ||
} | ||
|
||
public Builder replyTo( final String... replyTo ) | ||
{ | ||
this.replyTo.addAll( List.of( replyTo ) ); | ||
return this; | ||
} | ||
|
||
public Builder replyTo( final Collection<String> replyTo ) | ||
{ | ||
this.replyTo.addAll( replyTo ); | ||
return this; | ||
} | ||
|
||
public Builder subject( final String subject ) | ||
{ | ||
this.subject = subject; | ||
return this; | ||
} | ||
|
||
public Builder contentType( final String contentType ) | ||
{ | ||
this.contentType = contentType; | ||
return this; | ||
} | ||
|
||
public Builder body( final String body ) | ||
{ | ||
this.body = body; | ||
return this; | ||
} | ||
|
||
public Builder addHeader( final String key, final String value ) | ||
{ | ||
this.headers.add( MailHeader.from( key, value ) ); | ||
return this; | ||
} | ||
|
||
public void addHeaders( final Map<String, String> headers ) | ||
{ | ||
headers.forEach( this::addHeader ); | ||
} | ||
|
||
public Builder addAttachment( final MailAttachment attachment ) | ||
{ | ||
this.attachments.add( attachment ); | ||
return this; | ||
} | ||
|
||
public Builder addAttachments( final Collection<MailAttachment> attachments ) | ||
{ | ||
this.attachments.addAll( attachments ); | ||
return this; | ||
} | ||
|
||
public SendMailParams build() | ||
{ | ||
return new SendMailParams( this ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ | |
String smtpPassword() default ""; | ||
|
||
boolean smtpTLS() default false; | ||
|
||
String defaultFromEmail(); | ||
} |
Oops, something went wrong.