JavaMail API

JavaMail API

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









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.
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
what is java mail API - JavaMail
what is java mail API  Please tell me in detail what is java mail API
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
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
Artifacts of javamail
List of Artifacts of javamail maven depenency
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
Maven Repository/Dependency: javamail | javamail
Maven Repository/Dependency of Group ID javamail and Artifact ID javamail. Latest version of javamail:javamail dependencies. # Version Release Date You can read more at: Maven
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
javamail
Version of geronimo>javamail dependency
List of Version of geronimo>javamail dependency
Version of javamail>mail dependency
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
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.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.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  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 Repository/Dependency: org.jvnet.mock-javamail | mock-javamail
Maven Repository/Dependency of Group ID org.jvnet.mock-javamail and Artifact ID mock-javamail. Latest version of org.jvnet.mock-javamail:mock-javamail dependencies. # Version Release Date
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
java mail - JavaMail
java 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
Javamail - JavaMail
Javamail - JavaMail
Version of ant>ant-javamail dependency
List of Version of ant>ant-javamail dependency
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
mailing system in java - JavaMail
://www.roseindia.net/javamail/ Thanks
java complilation error - JavaMail
java 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.
java code - JavaMail
for more information. http://www.roseindia.net/javamail/FolderInfo.shtml
regarding sending mesage - JavaMail
://www.roseindia.net/javamail/ Thanks
Maven Dependency javamail >> 1.0
You should include the dependency code given in this page to add Maven Dependency of geronimo >> javamail version1.0 in your project
Version of geronimo>geronimo-javamail-transport dependency
List of Version of geronimo>geronimo-javamail-transport dependency
JAVA MAIL - JavaMail
application using JAVA MAIL API.  Hi Friend, Please explain us what code
Maven Dependency ant-javamail >> 1.6
You should include the dependency code given in this page to add Maven Dependency of ant >> ant-javamail version1.6 in your project
Maven Dependency ant-javamail >> 1.6.1
You should include the dependency code given in this page to add Maven Dependency of ant >> ant-javamail version1.6.1 in your project
Maven Dependency ant-javamail >> 1.6.2
You should include the dependency code given in this page to add Maven Dependency of ant >> ant-javamail version1.6.2 in your project
Maven Dependency ant-javamail >> 1.6.3
You should include the dependency code given in this page to add Maven Dependency of ant >> ant-javamail version1.6.3 in your project
Maven Dependency ant-javamail >> 1.6.4
You should include the dependency code given in this page to add Maven Dependency of ant >> ant-javamail version1.6.4 in your project

Ads