I want an email to be sent automatically. I am implementing this thing with the help of struts framework. I need to send an email where there will be an URL of a particular portal and the email body should contain a table with two columns but the number of rows is not fixed.
Asked
Active
Viewed 6,985 times
0
-
Same as you do in HTML – Ajinkya Jun 17 '13 at 09:37
-
1Send it as html? How to do it -> http://stackoverflow.com/questions/5068827/how-do-i-send-html-email-via-java – Augusto Jun 17 '13 at 09:38
-
Can you please tell us [what you have tried](http://mattgemmell.com/2008/12/08/what-have-you-tried/) so far, besides asking us? – Uwe Plonus Jun 17 '13 at 09:38
-
In JavaMail I've cheated by creating the Mail in the User-Client (Thunderbird), looking at the source code and transfering it in my project. Maybe it's a solution fitting for you, too. Cheers! – SimonSez Jun 17 '13 at 09:41
-
can you upload your code? – KhAn SaAb Jun 17 '13 at 09:56
-
I have cast a delete vote on this. – halfer Jul 26 '19 at 22:17
2 Answers
2
Your email can be an HTML email. So you'd use HTML to implement the table, and set the email mime type headers accordingly.
This answer tells you how to set the mime type correctly.

Community
- 1
- 1

Rajesh J Advani
- 5,585
- 2
- 23
- 35
0
first create your table
as in String format then set that String in setMsg()
MultiPartEmail htmlEmail = new HtmlEmail();
email.setSmtpPort(getPortNumber());
// authenticating the user
email.setAuthenticator(new DefaultAuthenticator(getSenderID(),
getSenderPassword()));
// email.setDebug(true);
email.setSSL(true);
//
email.setTLS(true);
// setting the host name
email.setHostName(getHostName());
// setting the rciever id
email.addTo(receiverId);
email.setFrom(getSenderID());
// setting the subject of mail
email.setSubject(getSubject());
email.setMsg("<table border="1"><tr><td></td></tr>");//here is your html code
email.send();

KhAn SaAb
- 5,248
- 5
- 31
- 52
-
Thank you guys for your quick response.I have used a while loop in my action class method and included that table inside that while loop.The table I created is simple html code inside the message body. – Mainak Jun 27 '13 at 08:27