Read the email using java mail api for Imap account which is secured SSL
hello,
I am trying read the new mails on my imap account... i am not able to connect to the imap account... could anyone help me out ..
below is the code
public class EmailImapGateway implements MessageCountListener{
private static final long serialVersionUID = 1L;
private Session session = null;
private IMAPStore store = null;
private IMAPFolder folder = null;
Properties props = new Properties();
public void ejbCreate() {
try {
if (session == null)
session = Session.getDefaultInstance(props, null);
if (store == null || !store.isConnected()) {
String host, name, passwd;
host = "host";
name = "user";
passwd = "passwd";
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
props.setProperty("mail.imap.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.socketFactory.port", "888");
java.security.Security.setProperty( "ssl.SocketFactory.provider", SSL_FACTORY);
props.put("mail.imap.host", host);
props.put("mail.imap.port", "888");
store = (IMAPStore) session.getStore("imap");
store.connect();
folder = (IMAPFolder) store.getFolder("Inbox");
folder.open(Folder.READ_WRITE);
int t = folder.getUnreadMessageCount();
System.out.println("getunreadmessagecount is :" + t);
}catch (Exception e) {
e.printStackTrace();
} finally {
try {
folder.close(true);
store.close();
} catch (MessagingException e) {
e.printStackTrace();
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
public void ejbRemove() {
// TODO Auto-generated method stub
public void messagesAdded(MessageCountEvent arg0) {
System.out.println("Message is added in inbox");
public void messagesRemoved(MessageCountEvent arg0) {
System.out.println("Message is removed from inbox");
it is not able to connect to my account
Edited by: bhavna84 on Sep 8, 2008 11:10 PM
Edited by: bhavna84 on Sep 8, 2008 11:20 PM
Yes, see my previous post.
He replied:
hello
In your code ur mention IMAP port 888
but by default its 143 so chk your server configuration for IMAP port no.
Similar Messages
-
Problem in retrieving email using java mail api
hi,
In my project,i am retrieving mails from a particular email id.
I am able to retrieve the latest mails and save it in a folder in my system.
The problem is whenever i run the program eventhough the most recently received mail in inbox is retrieved and saved,again it is retrieving the same one and saving it in the same folder(not repeating).
I tried to check the newmessages in the inbox using the folder.hasNewMessage() method in java mail api,but the method is returning false only regardless new mail is there in inbox or not.
I want to read the unread messages only.Dont want to retrieve the already read mails.
I got the mail retrieving code from the below site.(sorry not posting the code because it is so long and having 4 classes)
http://www.builderau.com.au/program/java/soa/Getting_the_mail_in_receiving_in_JavaMail/0,39024620,39228060,00.htm
Can anyone tell me how to read unread mails in the inbox?
Thanks a lothi parvathi
i think your mail program is receving mails using imap
the imap is only receve the mail from server but the pop is deleting the mails after receving
use the following sample code
package com.sfrc.mail.pop;
import javax.mail.*;
import javax.mail.internet.*;
import com.sun.mail.handlers.message_rfc822;
import java.util.*;
import java.io.*;
* Owner: SFRC IT Solutions Pvt Ltd
* Author:Arunkumar Subramaniam
* Date :12-06-2006
* File Name: AttachRecive.java
public class AttachRecive
public static void main(String args[])
try
String popServer="192.168.1.1";
String popUser="pl";
String popPassword="password";
// Create empty properties
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(popServer, popUser, popPassword);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message =folder.getMessages();
Multipart mp = (Multipart)message.getContent();
for (int i=0, n=mp.getCount(); i<n; i++) {
Part part = mp.getBodyPart(i);
String disposition = part.getDisposition();
// Close connection
folder.close(false);
store.close();
catch (Exception ex)
System.out.println("Usage: "
+" popServer popUser popPassword");
System.exit(0);
Regards
Arunkumar Subramaniam
SFRC IT Solutions Pvt Ltd
Chennai -
Attach multiple emails to one master email using Java mail API
Java version: JDK 1.5.0_15
Hi,
I am using Java API to send email using our corporate microsoft exchange server. Everything is working fine, now I have a requirement to attach multiple emails to one master email and send.
Question:
Using JAVA API is it possible to attach multiple emails to one email?
Regards,
ArupThe beginning of this FAQ entry tells you how to attach one message to another message:
http://www.oracle.com/technetwork/java/javamail/faq/index.html#forward -
How to receive HTML email using JAVA Mail API?
Hello!
I am developing WEB Mail System. There is a little problem. I am unable to receive mail in HTML format. The mail is being received in only text format currently. What method do i need to use to achieve this functionality currently i am using
MimeMessage message = mail.getMessage();
if(message.isMimeType("text/plain")){
String str_message_body = message.getContent().toString();
else
Multipart multipart = (Multipart)message .getContent();
Kindly advise me regarding that because i am in a state of fix right now and unable to proceed further.
I will really appreciate a prompt response from you.
Regards,
Burhan Ramay.HTML is a text format too, so you do
if(message.isMimeType("text/html")){
String str_message_body = message.getContent().toString();
} -
Using Java Mail API from Tomcat
Hello,
Purely as an academic exercise I have written a JSP page which, upon being requested from the client's browser, should send me a default email using Java Mail Api.
here is the code :
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class TestMail {
static String msgText1 = "success this time 12";
static String msgText2 = "This is the text in the message attachment.";
public String sendIt() {
String to = "<my email";
String from = "<anything>";
String host = "<my ip address of smtp server>";
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.host", host);
Session session = Session.getInstance(props, null);
.....The code works fine as a stand alone app but when called from JSP page it hangs on the Session.getInstance line. I can only guess that this might be a security issue with the container not allowing access to the smtp server ?
Can anyone give me a clue ???Your Tomcat log files should spell out the problem for you.
My Tomcat installation does not come with the Java Mail API. I had to add the mail and activation jar files to the server/common.lib directory (or the server's shared/lib or the WEB-INF/lib of your application.)
HTH. -
Can i use java mail APIs to read Unix mail
hi
can i use java mail APIs to read Unix mail?
Unix has "mail" command which can be used to access mails on the Unix system.
is it possible to execute mail & access unix mails remotely using POP/IMAP
thanks in advanceThere are JavaMail providers that allow you to access the Unix mail spool files directly. Alternatively the standard JavaMail API can access a POP or IMAP server, if one is installed.
-
Using Java mail API from JSPDynPage
Hi Experts,
I am working on a Portal Assignment that requiresto sent work flow mails on the basis of error conditions.
Can u please suggest if at all I can use Java Mail APIs from JSP page within the JSP DYN Page Framework.
If at all Java Mail can be used could u please suugest some help docs on the same.
Thanks for the help.
Manab C Ghosh
EP Consultant
Kolkata INDIA
+919830603327Hi Experts,
Thanks for all the responses to my Mail question(mailing from JSPDynPage).
I have found the solution.
Here is how I have got the things: (pls note there are other solns)
Using Java Mail APIs;
Create a Java file in the scr.core / src.api
MailSender.java
* Created on Jul 21, 2005
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
package com.mailsend.test;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
* Edited on Jul 24, 2005
* @author Manab C Ghosh
public class MailSender {
public String sendMessage(){
String msg ="Hello mail Test";
String smtpServer ="mySMTPServer";
String smtpSender = "senderemailaddress";
String smtpRecipient="receipientemailaddress";
String stBody = msg ;
//String stDate = new Date().toString() ;
String stSubject = "Mail Test ";
Send( smtpServer, //SMTPServer
smtpSender, //Sender
smtpRecipient, //Recipient
stSubject, //Subject
stBody //Body
); //Attachments
return "Mail Success";
public static void Send(String SMTPServer,
String From,
String To,
String Subject,
String msgText1
// Error status;
int ErrorStatus = 0;
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", SMTPServer);
Session session = Session.getDefaultInstance(props, null);
try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(From));
InternetAddress[] address = {new InternetAddress(To)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(Subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
//mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
} catch (MessagingException mex) {
Call this file from the JSP page (which is set at JSPDynPage controller)
one important thing-----
Create a dir under PORTAL-INF and import the following jars-- activation.jar, mail.jar,imap.jar,smtp.jar, mailapi.jar.
This works..
Thanks once again to the Experts.
happy mailing
Manab Ghosh.
INDIA (+919830603327) -
How to do SAVE AS DRAFT using java mail api
Hello,
I want to know how to do SAVE AS DRAFT using Java mail Api.
thanksHello,
I want to know how to do SAVE AS DRAFT using Java
mail Api.
thanksI don't think you can. That sounds like a feature of a mail client app itself. The Java mail API is for when you're ready to actually send the thing. Saving drafts is storing them somewhere like you would any other data; nothing to do with the mail API. -
How to use Java Mail API in Unix
I am trying to write some code using Java mail API. I want to execute it in Unix. I downloaded the mail API to windows machine and ftped the mail.jar file to a Unix machine. Then I set the class path as below:
export CLASSPATH=$CLASSPATH:/home.../mail.jar
Then I tried to compile my Java program. The output is as below:
error: error reading /home.../mail.jar; invalid END header (bad central directory offset)
mail.java:1: package javax.mail does not exist
import javax.mail.*;
Can any one please help me out.You should also include the "activation.jar" file that you obtained from
downloading the Java Activation Framework, in your CLASSPATH.
For example:
export CLASSPATH=$CLASSPATH:/urPath/activation/activation.jar
Besides, assuming you unzipped javamail-1_4_1.zip in home/download the following should work
export CLASSPATH=$CLASSPATH:home/download/javamail-1.4.1/mail.jar:. -
Problem using Java Mail API with WLS 7.0
Hi All,
I am trying to use the Java Mail API provided by WLS 7.0. I have made the
settings metioned in the WLS 7.0 docs. However when I try to run the program I
am getting the following error:
javax.naming.NoInitialContextException: Need to specify class name in environment
or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
46)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:283)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
The code that I have written is as follows
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try
//Context ic = getInitialContext();
InitialContext ic = new InitialContext();
/* My jndi name is "testSession" */
Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
IN THIS LINE */
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
/* For security reasons I have written the ip add in this format */
props.put("mail.from", "[email protected]"); /* for security reasons i have
changed the mail address */
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
public static Context getInitialContext()
throws NamingException
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
p.put(Context.SECURITY_PRINCIPAL, "weblogic");
p.put(Context.SECURITY_CREDENTIALS, "weblogic");
return new InitialContext(p);
}//end of class
Can anyone please tell me what is the problem. I thought that we cannot directly
do
InitialContext ic = new InitialContext();
So I had written a method getInitialContext() as shown in the above piece of code,
but that too did not work.
Eagerly awaiting a response.
Jimmy ShahYou can use InitialContext ic = new InitialContext() only if you are using a startup class, servlet or a JSP i.e
server side code.
If you are using a java client you need to use Context ic = getInitialContext();
Try this code
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try {
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ic = new InitialContext(h);
Session session = (Session) ic.lookup("testSession");
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
props.put("mail.from", "[email protected]");
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
}//end of class
We have shipped a javamail example in the samples\server\src\examples\javamail folder.
Jimmy Shah wrote:
Hi All,
I am trying to use the Java Mail API provided by WLS 7.0. I have made the
settings metioned in the WLS 7.0 docs. However when I try to run the program I
am getting the following error:
javax.naming.NoInitialContextException: Need to specify class name in environment
or system property, or as an applet parameter, or in an application resource file:
java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
46)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
a:283)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
The code that I have written is as follows
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
public class MailTo {
public static void main(String args[])
try
//Context ic = getInitialContext();
InitialContext ic = new InitialContext();
/* My jndi name is "testSession" */
Session session = (Session) ic.lookup("testSession"); /* THE PROBLEM IS SHOWN
IN THIS LINE */
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "XX.XX.XX.XX");
/* For security reasons I have written the ip add in this format */
props.put("mail.from", "[email protected]"); /* for security reasons i have
changed the mail address */
Session session2 = session.getInstance(props);
Message msg = new MimeMessage(session2);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]",
false));
msg.setSubject("Test Message");
msg.setSentDate(new Date());
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText("This is a mail sent to you using JAVA Mail API and Weblogic Server");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
catch(Exception e)
e.printStackTrace();
}//end of main
public static Context getInitialContext()
throws NamingException
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7501/testWebApp");
p.put(Context.SECURITY_PRINCIPAL, "weblogic");
p.put(Context.SECURITY_CREDENTIALS, "weblogic");
return new InitialContext(p);
}//end of class
Can anyone please tell me what is the problem. I thought that we cannot directly
do
InitialContext ic = new InitialContext();
So I had written a method getInitialContext() as shown in the above piece of code,
but that too did not work.
Eagerly awaiting a response.
Jimmy Shah--
Rajesh Mirchandani
Developer Relations Engineer
BEA Support -
Using java mail api without servlets, I ve sent an html mail. In that Ive
Using java mail api without servlets, I ve sent an html mail. In that Ive specified action to the servlet. On click, it shows url as file:///C:/Documents%20and%20Settings/sirivanig/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/CNFHMDIT/updatemailerform%5B2%5D.htm instead of www.servername.com/....
May I know the reason why it shows like this.
Do I ve to send htmlmail through servlet so that it does show proper url?Possibly your mailer is restricting your access to URLs to prevent
various scams. Without the details, it's hard to know what's going
wrong.
Have you tried with a different mailer? -
How can i access gmail's smtp server using java mail api
i m using java mail api to access gmails pop and smtp service to receive and send mail from ur gmail account. I m able to access gmails pop server using the ssl and port 995 , but i can not use its smtp server to which i m connecting using ssl on 465 port. It requires authentication code.
if anybody can help me in this regard i m thnkful to him/her.
thnks in advance.
jogin desaiHere's an example of using SSL + Authentication
http://onesearch.sun.com/search/onesearch/index.jsp?qt=ssl+authentication&subCat=siteforumid%3Ajava43&site=dev&dftab=siteforumid%3Ajava43&chooseCat=javaall&col=developer-forums -
How Can I Turn OFF Junk Mail Filter for IMAP Accounts Only?
I am trying to figure out how to turn off the Junk Mail filtering for IMAP accounts such as .Mac/.ME and GMAIL. All filtering is working fine on the server side, and reviewing the mail that is tagged is easy enough by just going to the account and displaying the folders created on the server.
I've checked the Junk mail pref and although the Advance settings let you isolate specific accounts to check, it does not give you the option bypass checking an account.
i.e.
if <Any> of the following conditions are met:
<Account> <is not> <Gmail (IMAP)>
As is, the mail rules are working perfectly on the server side, but in Apple Mail, many mails are being sent the Apple Mail's Junk folder.
When going through the Gmail's instructions on setting up a Gmail account for Apple Mail, it specifically says to turn off Junk mail filtering for the account, but I can't find any options to do that.
Any help or suggestions would be greatly appreciated.
TIAI haven't tried this, but it should work:
Make a new rule,
If <Any> <Account> is <Gmail> or <Account> is <.me> then "Stop evaluating rules".
Move this rule to the last in the list of rules.
In the Junk Mail preferences, be sure that "Filter junk mail before applying my rules" is unchecked. -
Save Attachment from exchange server 2010 from oracle using java mail API
Hello,
I want to read email from microsoft exchangeserver 2010 and save attachement into a folder.I created an Java program to import attachments from a exchange server mailbox using "POP3S".It works fine when run as a java application.But when i put this inside Oracle11g R2 using load java and while executing from a procedure it gives an error at parsing message into Multipart
Error at line : Multipart mp = (Multipart)m.getContent();
Error:
Content-Type: multipart/mixed;
boundary="_002_A0C2E09A..................................."
java.lang.ClassCastException
at mailPop3.checkmail(mailPop3:71)
My Java Class is as follows,
import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Date;
The function i used to check for attachments is given below.
public static boolean hasAttachments(Message m) throws java.io.IOException, MessagingException
Boolean hasAttachments = false;
try
// if it is a plain/html text - no attachements
if (m.isMimeType("text/*"))
return hasAttachments;
else if (m.isMimeType("multipart/alternative"))
return hasAttachments;
else if (m.isMimeType("multipart/*"))
Multipart mp = (Multipart)m.getContent();
if (mp.getCount() > 1)
hasAttachments = true;
return hasAttachments;
catch (Exception e) {
e.printStackTrace();
} finally {
return hasAttachments;
My Java Details as follows
java Version :1.5.0_10
java.vm.specification.version:1.0
java.vm.version :1.5.0_01
java.specification.version:1.5
java.class.version:48.0
Java mail API:javamail-1.4.4
Used Jars:mail.jar
Could someone explain why I am getting this error? What can I do to resolve this error?
Is any other Jar need other than mail.jar?
Any help would be much appreciated.
Regards,
NisanthHai EJP,
Thanks for your reply,
My full java class as follows,
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Part;
import javax.mail.Multipart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeMessage;
public class Newmail
public Newmail()
super();
public static int mailPOP3(String phost,
String pusername,
String ppassword)
Folder inbox =null;
Store store =null;
int result = 1;
try
String host=phost;
final String username=pusername;
final String password=ppassword;
System.out.println("Authenticator");
Authenticator auth=new Authenticator()
protected PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication(username, password);
System.out.println("Certificate");
String filename="D:\\Certi\\jssecacerts";
String password2 = "changeit";
System.setProperty("javax.net.ssl.trustStore",filename);
System.setProperty("javax.net.ssl.trustStorePassword",password2);
Properties props = System.getProperties();
System.out.println("host-----"+props);
props.setProperty("mail.pop3s.port", "993");
props.setProperty("mail.pop3s.starttls.enable","true");
props.setProperty("mail.pop3s.ssl.trust", "*");
Session session = Session.getInstance(props,auth);
session.setDebug(true);
store = session.getStore("pop3s");
System.out.println("store------"+store);
store.connect(host,username,password);
System.out.println("Connected...");
inbox = store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message[] msgs = inbox.getMessages();
System.out.println("msgs.length-----"+msgs.length);
result = 0;
int no_of_messages = msgs.length;
for ( int i=0; i < no_of_messages; i++)
System.out.println("msgs.count-----"+i);
System.out.println("Attachment....>"+msgs.getContentType());
Multipart mp = (Multipart)msgs[i].getContent();
System.out.println("Casting Success" + mp.getContentType());
catch(Exception e)
e.printStackTrace();
finally
try
if(inbox!=null)
inbox.close(false);
if(store!=null)
store.close();
return result;
catch(Exception e)
e.printStackTrace();
return result;
Please check it
Regards,
Nisanth -
Problem in sending messages using java mail api
Hi All,
I have a problem in sending messages via java mail api.
MimeMessage message = new MimeMessage(session);
String bodyContent = "ñSunJava";
message.setText (bodyContent,"utf-8");using the above code its not possible for me to send the attachment. if i am using the below code means special characters like ñ gets removed or changed into some other characters.
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setText(bodyText);
// Set the email attachment file
MimeBodyPart attachmentPart = new MimeBodyPart();
FileDataSource fileDataSource = new FileDataSource("C:/sunjava.txt") {
public String getContentType() {
return "application/octet-stream";
attachmentPart.setDataHandler(new DataHandler(fileDataSource));
attachmentPart.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messagePart);
multipart.addBodyPart(attachmentPart);
message.setContent(multipart);
Transport.send(message);is there any way to send the file attachment with the body message without using MultiPart java class.Taken pretty much straight out of the Javamail examples the following works for me (mail read using Thunderbird) // Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
// Set the 'to' address
for (int i = 0; i < to.length; i++)
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set the 'cc' address
for (int i = 0; i < cc.length; i++)
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
// Set the 'bcc' address
for (int i = 0; i < bcc.length; i++)
message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
message.setSubject("JavaMail With Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Here's the file ñSunJava");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
for (int count = 0; count < 5; count++)
String filename = "hello" + count + ".txt";
String fileContent = " ñSunJava - Now is the time for all good men to come to the aid of the party " + count + " \n";
// Create another body part
BodyPart attachementBodyPart = new MimeBodyPart();
// Get the attachment
DataSource source = new StringDataSource(fileContent, filename);
// Set the data handler to this attachment
attachementBodyPart.setDataHandler(new DataHandler(source));
// Set the filename
attachementBodyPart.setFileName(filename);
// Add this part
multipart.addBodyPart(attachementBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
Maybe you are looking for
-
I have an Iphone 4 on the latest IOS 5 and latest 2.3 remote control app as I use Itunes 10 to manage the phone. Since version 10 of Itunes the airport express output has been degraded with a digital volume control so I refuse to use version 10 for m
-
Re-connecting Elements 9 to a New Location
I have copied all my images - around 500Gb - to a new (larger) external Hard Drive. The transfer took about 16 hours. Can anyone advise how I move/reconnect the Adobe Elements catalog to point to the new location? The answer I'd not like to hear is
-
Hi this is DETARIS I have a question for the I pad mini
I want to buy online the Ipad mini 16gb Wifi but it can work in greece?and how long will take to receive it?
-
Hello, Thanks in advance for your help. I am attempting to allow users of Adobe Reader to attach their own documents to a PDF such that their documents get encrypted during the attachment. I know that I can do this in Adobe Acrobat (via Security En
-
I cannot connect wifi on my fone it says authentication problem
i cannot connect to my fone with wifi from my osprey