JavaMail API

Ads

 
 

Share on Google+Share on Google+

satish
JavaMail API
2 Answer(s)      9 years ago
Posted in : JavaMail
Ads
View Answers

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) {
}

}
}




June 25, 2008 at 1:33 PM


Hi friend,



Read for more information about Mail API:

http://www.roseindia.net/mail/sending-an-email-in-jsp.shtml


Thanks

Ads









Related Tutorials/Questions & Answers:
JavaMail API usage - JavaMail
JavaMail 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 - JavaMail
JAVAMAIL API  This is my code, but i got unnecessary data like ???]???????????? € ??? this how to avoid this WELCOME  
Advertisements
JavaMail API - JavaMail
JavaMail 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 API
gmail 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 - JavaMail
-in-jsp.shtml http://www.roseindia.net/javamail/ Thanks
Java Mail API - JavaMail
Java 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.
what is java mail API - JavaMail
what is java mail API  Please tell me in detail what is java mail API
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
Version of javamail>javamail dependency
List of Version of javamail>javamail dependency
javamail in jsp - JavaMail
javamail 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
Artifacts of javamail
List of Artifacts of javamail maven depenency
JavaMail flagging problems - JavaMail
JavaMail 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 - JavaMail
Mailing  Dear Friends, How can i send mails to yahoo,gmail,other mail servers using javamail using a jsp file. Please help me
java - JavaMail
java  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 - JavaMail
java  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
forgotpassword - JavaMail
with running example. http://www.roseindia.net/javamail/ Thanks
extract content from javamail - JavaMail
extract 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
Version of geronimo>javamail dependency
List of Version of geronimo>javamail dependency
JAVA MAIl - JavaMail
JAVA 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
Maven Dependency javamail >> 1.3.1
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.1 in your project
Maven Dependency javamail >> 1.3.2
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.2 in your project
Maven Dependency javamail >> 1.3.3
You should include the dependency code given in this page to add Maven Dependency of javamail >> javamail version1.3.3 in your project
JSP - JavaMail
JSP  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
javascript - JavaMail
("Message Send....."); } } Thanks  Hi friend, Mail API
Java Mail - JavaMail
Java 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 - JavaMail
sending 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-Servlet
JavaMail 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

Ads

 
Advertisement null

Ads