June 25, 2008 at 11:25 AM
Hi Satish,
Use the following code to send mails to multiple recipients.
The following code is tested and working fine.
Regards,
Pradeep
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
import java.util.StringTokenizer;
/** @author Pradeep
* MailNotifier - a utility class to send a SMTP mail notification
*
* **/
public class MailNotifier {
private Session session = null;
private static MailNotifier notifierInstance = new MailNotifier();
public static MailNotifier getInstance()
{
return notifierInstance;
}
private MailNotifier()
{
Properties p = new Properties();
p.put("mail.host", "mail.ca.com");
p.put("mail.user", "SENDER");
session = Session.getDefaultInstance(p, null);
}
public void sendMail() throws Exception
{
String to = "sendermailid1;sendermailid2";
MimeMessage msg = new MimeMessage(session);
msg.setText("Body of the your mail");
msg.setSubject("Subject of the mail");
Address fromAddr = new InternetAddress("Sender");
msg.setFrom(fromAddr);
StringTokenizer st = new StringTokenizer(to,";");
Address[] toAddr = new Address[st.countTokens()];
int i =0;
while(st.hasMoreTokens()){
String s = st.nextToken();
toAddr[i] = new InternetAddress(s);
i++;
}
//toAddr = new InternetAddress(to);
msg.addRecipients(Message.RecipientType.TO, toAddr);//to send mails in TO list
//msg.addRecipients(Message.RecipientType.CC, toAddr); //to send mails in CC list
Transport.send(msg);
}
public static void main(String args[]){
MailNotifier mailNotifier = MailNotifier.getInstance();
try {
mailNotifier.sendMail();
} catch (Exception e) {
}
}
}
Related Tutorials/Questions & Answers:
JavaMail API usage - JavaMailJavaMail API usage Hello sir,
i wrote a program to send a message from one mail account to another
mail account,for that i uses JAVA and JSP two.../
javamail/
Thanks.
Amardeep
JAVAMAIL API - JavaMailJAVAMAIL API This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this
WELCOME
Advertisements
JavaMail API - JavaMailJavaMail API Hi My Name is Satish
I have a Problem with Java Mail
API when I am doing Maling programme I can able to do single mail and single CC...) {
}
}
}
Hi friend,
Read for more information about Mail
API:
http
gmail access using javamail APIgmail access using
javamail API how to coonect to gmail using java mail
API ? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
Java Mail API - JavaMailJava Mail API Hi!
I wish u advanced happy new year to all of ur team members....
My question is..
I want to read attachments in my gmail account using java mail
api... i got code from our roseindia.net i.e.
get from address using javamail api?get from address using
javamail api? i want to get from address of particular mail using the
javamail api?
actually i had done it in one .jsp file using the particular mail number.
message[messageno].getFrom()[0
javamail in jsp - JavaMailjavamail in jsp Hii Sir,
I am working wuth a
javamail programme now and i can send the mail with in the compony mail server but cant mail between other gmail , yahoo or any other mail servers. I got an exception
JavaMail flagging problems - JavaMailJavaMail flagging problems Hi everyone, I am working on receiving a mail currently. I use a substring "status" to search for the mail's subject line... the following link:
http://www.roseindia.net/
javamail/
Here you will get
Mailing - JavaMailMailing Dear Friends,
How can i send mails to yahoo,gmail,other mail servers using
javamail using a jsp file.
Please help me
java - JavaMailjava Hi,
i want to send a mail automatically particular time for every day
so, please reply me Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that that above link
java - JavaMailjava How to send out an email using simple java How to send out an email with attachment using simple java Hi Friend,
Please visit the following links:
http://www.roseindia.net/
javamail/
Thanks
extract content from javamail - JavaMailextract content from javamail Hi,
I currently try the example(Read Multipart mail using Java Mail) on
Javamail from the site to receive the e-mail. Then If I going to extract text the message content. What can I do
java mail error - JavaMail. Please visit the following link to know more about use of Java Mail
API.
http://www.roseindia.net/
javamail
Thanks
RoseIndia Team
sent mail code - JavaMail . This link contains examples over the Java Mail
API..
http://www.roseindia.net/
javamail
Hope that this will be helpful to you.
Thanks
RoseIndia Team
JSP - JavaMailJSP Hi!
I am trying to view my attachments in my mail through JAVA MAIL
API. this is my code which i got from roseindia.
import java.io.*;
import java.util.*;
import javax.mail.*;
public class ReadAttachment
JAVA MAIl - JavaMailJAVA MAIl Hi,
I am trying to send a mail using java mail
api. But I am getting following error:
javax.mail.SendFailedException: Sending failed...:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you
Java Mail - JavaMailJava Mail how to email using Java mail or automatic generated mail??? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
sending emails - JavaMailsending emails what is the code for sending emails in java Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
JavaMail and Gmail - JSP-ServletJavaMail and Gmail In my previous question, I forgot to mention that following exception is arising when trapped in catch:
javax.mail.MessagingException: can't determine local email address
Kindly let me know
java mail - JavaMailjava mail how to send a mail without authentication in java ? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
javamail/
Hope that it will be helpful for you.
Thanks
regarding email - JavaMail, port: 25"
is that you've incorrectly configured your properties and
JavaMail... or not?
If not, then something has happened to the Properties that
JavaMail...://www.roseindia.net/
javamail/
Thanks
java complilation error - JavaMailjava complilation error Hi
I was trying to send the mails using the below code,This coding is giving errors that
java.mail.* does not exists,i am using netbeans 6.5 ide...pls help
mail.jsp
<@pageimport="java.util.
Maven Dependency javamail >> 1.0You should include the dependency code given in this page to add Maven Dependency of geronimo >>
javamail version1.0 in your project