@@ -49,84 +49,62 @@ protected PasswordAuthentication getPasswordAuthentication() {
49
49
50
50
/**
51
51
* @param subject The subject of the E-mail
52
- * Displays MessagingException on error
52
+ * @throws MessagingException
53
53
*/
54
- public void setSubject (String subject ){
55
- try {
56
- msg .setSubject (subject );
57
- } catch (MessagingException e ) {
58
- e .printStackTrace ();
59
- }
54
+ public void setSubject (String subject )throws MessagingException {
55
+ msg .setSubject (subject );
60
56
}
61
57
62
58
/**
63
59
* @param s The Body text to be added in the E-mail
64
- * Displays MessagingException on error
60
+ * @throws MessagingException
65
61
*/
66
- public void addText (String s ){
67
- try {
68
- MimeBodyPart mimeBodyPart =new MimeBodyPart ();
69
- mimeBodyPart .setText (s );
70
- multipart .addBodyPart (mimeBodyPart );
71
- } catch (MessagingException e ) {
72
- e .printStackTrace ();
73
- }
62
+ public void addText (String s )throws MessagingException {
63
+ MimeBodyPart mimeBodyPart =new MimeBodyPart ();
64
+ mimeBodyPart .setText (s );
65
+ multipart .addBodyPart (mimeBodyPart );
74
66
}
75
67
76
68
/**
77
69
* @param file The file to be attached in the E-mail in the form of File object
78
- * Displays MessagingException on error
79
- * Displays IOException if file not found
70
+ * @throws MessagingException, IOException
80
71
*/
81
- public void addAttachment (File file ){
82
- try {
83
- MimeBodyPart mimeBodyPart =new MimeBodyPart ();
84
- mimeBodyPart .attachFile (file );
85
- multipart .addBodyPart (mimeBodyPart );
86
- } catch (IOException | MessagingException e ) {
87
- e .printStackTrace ();
88
- }
72
+ public void addAttachment (File file ) throws MessagingException , IOException {
73
+ MimeBodyPart mimeBodyPart =new MimeBodyPart ();
74
+ mimeBodyPart .attachFile (file );
75
+ multipart .addBodyPart (mimeBodyPart );
89
76
}
90
77
91
78
/**
92
79
* @param fileAddress The absolute path of the file to be attached in the E-mail
93
- * Displays MessagingException on error
94
- * Displays IOException if file not found
80
+ * @throws MessagingException, IOException
95
81
*/
96
- public void addAttachment (String fileAddress ){
97
- try {
98
- MimeBodyPart mimeBodyPart =new MimeBodyPart ();
99
- mimeBodyPart .attachFile (fileAddress );
100
- multipart .addBodyPart (mimeBodyPart );
101
- } catch (IOException | MessagingException e ) {
102
- e .printStackTrace ();
103
- }
82
+ public void addAttachment (String fileAddress ) throws MessagingException , IOException {
83
+ MimeBodyPart mimeBodyPart =new MimeBodyPart ();
84
+ mimeBodyPart .attachFile (fileAddress );
85
+ multipart .addBodyPart (mimeBodyPart );
104
86
}
105
87
106
88
/**
107
89
* Method to send the message
108
90
* @return true if the message is sent successfully or false if the message is not sent successfully
91
+ * @throws MessagingException
109
92
*/
110
- public boolean send (){
111
- try {
112
- msg .setFrom (new InternetAddress (fromAddress ));
113
- Message .RecipientType type ;
114
- switch (recipientType .toUpperCase ()){
115
- case "TO" : type =Message .RecipientType .TO ; break ;
116
- case "BCC" : type =Message .RecipientType .BCC ; break ;
117
- case "CC" : type =Message .RecipientType .CC ;break ;
118
- default : throw new IllegalStateException ("Unexpected value: " + recipientType );
119
- }
120
- for (String to :toAddress )
121
- msg .addRecipient (type ,new InternetAddress (to ));
122
- MimeBodyPart mimeBodyPart =new MimeBodyPart ();
123
- mimeBodyPart .setText ("" );
124
- multipart .addBodyPart (mimeBodyPart );
125
- msg .setContent (multipart );
126
- Transport .send (msg );
127
- return true ;
128
- } catch (MessagingException e ) {
129
- return false ;
93
+ public void send () throws MessagingException {
94
+ msg .setFrom (new InternetAddress (fromAddress ));
95
+ Message .RecipientType type ;
96
+ switch (recipientType .toUpperCase ()){
97
+ case "TO" : type =Message .RecipientType .TO ; break ;
98
+ case "BCC" : type =Message .RecipientType .BCC ; break ;
99
+ case "CC" : type =Message .RecipientType .CC ;break ;
100
+ default : throw new IllegalStateException ("Unexpected value: " + recipientType );
130
101
}
102
+ for (String to :toAddress )
103
+ msg .addRecipient (type ,new InternetAddress (to ));
104
+ MimeBodyPart mimeBodyPart =new MimeBodyPart ();
105
+ mimeBodyPart .setText ("" );
106
+ multipart .addBodyPart (mimeBodyPart );
107
+ msg .setContent (multipart );
108
+ Transport .send (msg );
131
109
}
132
110
}
0 commit comments