Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. public class SimpleSender {
  2.  
  3. public static void send(String smtpServer, String[] to, String[] cc, String from,
  4. String subject, String body, boolean HTML, String fullFilePath) {
  5. SendEmail(smtpServer, to, cc, from, subject, body, HTML, fullFilePath);
  6. }
  7. public static void send(String smtpServer, String[] to, String[] cc, String from,
  8. String subject, String body, boolean HTML) {
  9. SendEmail(smtpServer, to, cc, from, subject, body, HTML, null);
  10. }
  11.  
  12. // Should I provide this overload and similar ones?
  13. public static void send(String smtpServer, String to, String[] cc, String from,
  14. String subject, String body, boolean HTML) {
  15. SendEmail(smtpServer, new String[] {to}, cc, from, subject, body, HTML, null);
  16. }
  17. private static void SendEmail(String smtpServer, String[] to, String[] cc, String from, String subject, String body, boolean HTML, String fullFilePath) {
  18. .... Send email
  19. }
  20. }
  21.  
  22. public class EmailOptions {
  23. private final List<String> recepients;
  24. private final List<String> cc;
  25. private final List<String> bcc;
  26.  
  27. public void setHTML(boolean html) {
  28. this.html = html;
  29. }
  30.  
  31. ...
  32. }
  33.  
  34. public void sendEmail(EmailOptions email) {
  35. ...
  36. }
  37.  
  38. class EmailSender{
  39.  
  40. private final String body;
  41. private final String recipient;
  42. private final List<String> to;
  43. private final List<String> ccs;
  44.  
  45. public EmailSender(EMailBuilder mailBuilder){
  46. this.body = mailBuilder.body;
  47. this.to = mailBuilder.to;
  48. this.recipient = mailBuilder.recipient;
  49. this.ccs = mailBuilder.ccs;
  50.  
  51. }
  52. public void send(){
  53. //
  54. }
  55. public static class EMailBuilder{
  56.  
  57. private final String body;
  58. private final String recipient;
  59. private final List<String> to;
  60. private final List<String> ccs;
  61.  
  62. public EMailBuilder(String body,String recipient,String to){
  63. this.recipient = recipient;
  64. this.body = body;
  65. this.to = new ArrayList<>();
  66. this.to.add(to);
  67. this.ccs = new ArrayList<>();
  68.  
  69. }
  70.  
  71. public EMailBuilder addTo(String to){
  72. this.to.add(to);
  73. return this;
  74. }
  75. public EMailBuilder addCc(String cc){
  76. this.ccs.add(cc);
  77. return this;
  78. }
  79.  
  80. public EmailSender build(){
  81. EmailSender sender = new EmailSender(this);
  82. return sender;
  83. }
  84.  
  85. }
  86. }
  87.  
  88. EmailSender emailSender = new EmailSender.EMailBuilder("This is an email","me","you")
  89. .addTo("the Other Chap").addCc("the boss")
  90. .build();
  91. emailSender.send();
  92.  
  93. if(to.length==0){
  94. // invalid
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement