Subversion Repositories SmartDukaan

Rev

Rev 11451 | Rev 20152 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11451 Rev 12103
Line 264... Line 264...
264
			}
264
			}
265
 
265
 
266
			throw new MessagingException(e.getMessage(), e);
266
			throw new MessagingException(e.getMessage(), e);
267
		}
267
		}
268
	}
268
	}
-
 
269
	
-
 
270
	public void sendSSLMessage(String recipients[], String subject, String message, final String from, final String password, List<File> files, String htmlFileName) throws MessagingException {
-
 
271
		try {
-
 
272
			
-
 
273
			BufferedReader bufferedReader = new BufferedReader(new FileReader(htmlFileName));
-
 
274
 
-
 
275
			StringBuffer htmlContent = new StringBuffer();
-
 
276
			String line = null;
-
 
277
 
-
 
278
			while((line =bufferedReader.readLine())!=null){
-
 
279
 
-
 
280
				htmlContent.append(line).append("\n");
-
 
281
 
-
 
282
			}
-
 
283
			Message msg = prepareMessage(recipients, subject, from, password);
-
 
284
 
-
 
285
			//Create the multi-part object to hold the text and attachment parts
-
 
286
			Multipart multipart = new MimeMultipart();
-
 
287
			
-
 
288
			MimeBodyPart htmlPart = new MimeBodyPart();
-
 
289
 
-
 
290
			htmlPart.setContent(htmlContent.toString(), "text/html; charset=utf-8");
-
 
291
 
-
 
292
			// create the message part 
-
 
293
			MimeBodyPart messageBodyPart = new MimeBodyPart();
-
 
294
			//Part 1: Text message
-
 
295
			messageBodyPart.setText(message);
-
 
296
			multipart.addBodyPart(htmlPart);
-
 
297
 
-
 
298
			//Part 2: Attachment
-
 
299
			for (File file : files) {
-
 
300
				DataSource source = new FileDataSource(file);
-
 
301
				String[] names = file.getAbsolutePath().split("/");
-
 
302
				messageBodyPart = new MimeBodyPart();
-
 
303
				messageBodyPart.setDataHandler(new DataHandler(source));
-
 
304
				messageBodyPart.setFileName(names[names.length - 1]);
-
 
305
				multipart.addBodyPart(messageBodyPart);
-
 
306
			}
-
 
307
 
-
 
308
			// Put parts in message
-
 
309
			msg.setContent(multipart);
-
 
310
			Transport.send(msg);
-
 
311
		} catch (Exception e) {
-
 
312
			// If there is any error with normal mail sending, try diving receipients across domains
-
 
313
			if (hasMultipleDomains(recipients)) {
-
 
314
				for (List<String> subReceipients : getReceipientsPerDomain(recipients).values()) {
-
 
315
					sendSSLMessage(subReceipients.toArray(new String[0]), subject, message, from, password, files);
-
 
316
				}
-
 
317
 
-
 
318
				return;
-
 
319
			}
-
 
320
 
-
 
321
			throw new MessagingException(e.getMessage(), e);
-
 
322
		}
-
 
323
	}
269
 
324
 
270
 
325
 
271
	public static void main(String args[]) throws Exception {
326
	public static void main(String args[]) throws Exception {
272
		String[] sendTo = { "mandeep.dhir@shop2020.in", "mandeep.dhir@gmail.com", "mandeepcse07@yahoo.co.in", "kshitij.sood@shop2020.in" };
327
		String[] sendTo = { "mandeep.dhir@shop2020.in", "mandeep.dhir@gmail.com", "mandeepcse07@yahoo.co.in", "kshitij.sood@shop2020.in" };
273
		String emailSubjectTxt = "Another test from gmail";
328
		String emailSubjectTxt = "Another test from gmail";