Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SimpleSender {
- public static void send(String smtpServer, String[] to, String[] cc, String from,
- String subject, String body, boolean HTML, String fullFilePath) {
- SendEmail(smtpServer, to, cc, from, subject, body, HTML, fullFilePath);
- }
- public static void send(String smtpServer, String[] to, String[] cc, String from,
- String subject, String body, boolean HTML) {
- SendEmail(smtpServer, to, cc, from, subject, body, HTML, null);
- }
- // Should I provide this overload and similar ones?
- public static void send(String smtpServer, String to, String[] cc, String from,
- String subject, String body, boolean HTML) {
- SendEmail(smtpServer, new String[] {to}, cc, from, subject, body, HTML, null);
- }
- private static void SendEmail(String smtpServer, String[] to, String[] cc, String from, String subject, String body, boolean HTML, String fullFilePath) {
- .... Send email
- }
- }
- public class EmailOptions {
- private final List<String> recepients;
- private final List<String> cc;
- private final List<String> bcc;
- public void setHTML(boolean html) {
- this.html = html;
- }
- ...
- }
- public void sendEmail(EmailOptions email) {
- ...
- }
- class EmailSender{
- private final String body;
- private final String recipient;
- private final List<String> to;
- private final List<String> ccs;
- public EmailSender(EMailBuilder mailBuilder){
- this.body = mailBuilder.body;
- this.to = mailBuilder.to;
- this.recipient = mailBuilder.recipient;
- this.ccs = mailBuilder.ccs;
- }
- public void send(){
- //
- }
- public static class EMailBuilder{
- private final String body;
- private final String recipient;
- private final List<String> to;
- private final List<String> ccs;
- public EMailBuilder(String body,String recipient,String to){
- this.recipient = recipient;
- this.body = body;
- this.to = new ArrayList<>();
- this.to.add(to);
- this.ccs = new ArrayList<>();
- }
- public EMailBuilder addTo(String to){
- this.to.add(to);
- return this;
- }
- public EMailBuilder addCc(String cc){
- this.ccs.add(cc);
- return this;
- }
- public EmailSender build(){
- EmailSender sender = new EmailSender(this);
- return sender;
- }
- }
- }
- EmailSender emailSender = new EmailSender.EMailBuilder("This is an email","me","you")
- .addTo("the Other Chap").addCc("the boss")
- .build();
- emailSender.send();
- if(to.length==0){
- // invalid
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement