Using Java Mail to Access Hotmail
I'm writing an organizer program which currently handles contacts and a personal calendar. I want to add email functionality, starting with Hotmail access, since that's what I use.
Could you folks please point me in the direction of tutorials on how to access Hotmail or other HTML-based mail services using Java's Mail API?
thanks,
Andrew
JavaMail can be used to write an email application with an HTML interface like HotMail.
You will need some kind of mail server. POP3 does not support multiple folders on the server, all you have is an "inbox" and there is not supposed to be any way to push messages from a client to this folder (although some servers will allow you to do it).
If you are using a POP3 server and want to have multiple folders, you need to provide space on the application server which is running the servlet/jsp for the system.
You will also have to put together some session management for the HTTP/HTML pieces to know who the user is and what account on the mail server the user accesses.
Then you will need a file manager for managing the actual messages/files after they are taken off the mail server and placed on the application machine.
If you use an IMAP server all you need is an application server which will provide the interface that you want to write. Message management, in terms of message storage and folders, is built into the server and the JavaMail API provides an interface to it.
Sean
Similar Messages
-
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 to use java mail to send email to hotmail box
how to use java mail to send email to hotmail box??
i can send emails to other box(my company's email account) but for hotmail, the program didnt print any err or exception the recepient cant receive the mail.
thanksyou ust to download activation.jar and mail.jar and add them to your build path.
i have used the googlemail smtp server to send mail the code is following:
public void SendMail()
Properties props = new Properties();
props.put("mail.smtp.user", username);
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", port);
try{
Authenticator auth = new SMTPAuthenticator(username,password);
Session session = Session.getInstance(props, auth);
MimeMessage msg = new MimeMessage(session);
msg.setText(text);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(senderEmail));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(receiver));
Transport.send(msg);
}catch(Exception ex) {
System.out.println("Error Sending:");
System.out.println(ex.getMessage().toString());
and this the SMTPAuthenticator Class which you will need too.
class SMTPAuthenticator extends javax.mail.Authenticator {
private String fUser;
private String fPassword;
public SMTPAuthenticator(String user, String password) {
fUser = user;
fPassword = password;
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(fUser, fPassword);
} -
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. -
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? -
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.
-
How to delete message from the fodler of AOL account using Java mail
Hello All,
I am using Java MAil API in my application, i want to delete message from AOL account's folder,
when i set the folder as "Recently Deleted" or "Trash" , i get an exception as "folder does not exist".
when i tested , some times mail is moving into Recently Deleted folder, but not every time.
this is happening in both the interface as AOl Interface or my application.
when i use folder.close(true) after setting the flag of message as DELETED. it completely remove the message from the acount.
but i want to let the message be remained in the Recently Deleted folder. what should i do.
i dont want to remove the message completely from the account.I am using IMAP also.You'll need to figure out what the real name of the "Recently Deleted" folder is on the AOL IMAP server
(assuming it's a real folder and not some sort of "virtual" folder), then copy the message into that folder.
See the folderlist.java demo program as a way to explore the names of all the folders on the server. -
Error of using Java Mail in Web Start
Hi,
I got a problem when using Java Mail to send email. My apps is a stand alone and no problem when it was deployed normally. When I used the Web Start to deploy it, the following error was caught when I tried to send email:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_2824645.1032281188963"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1527)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:321)
at javax.mail.Transport.send0(Transport.java:164)
at javax.mail.Transport.send(Transport.java:81)
at com.mailcom.client.util.EMail.sendMail(EMail.java:180)
Here is the source code:
public class EMail {
public static void sendMail(String host,
String sender,
String recipient,
String subject,
String content,
Vector fileNames) throws MessagingException {
Properties props = new Properties();
props.put("mail.smtp.host",host);
Session session = Session.getDefaultInstance(props,null);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(sender));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient,false));
msg.setSubject(subject);
Multipart mp = new MimeMultipart();
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(content);
mp.addBodyPart(mbp1);
// attach the file to the message
if(fileNames != null && fileNames.size() != 0) {
FileDataSource fds = null;
for(int i = 0; i < fileNames.size(); i++ ) {
String currentFileName = (String)fileNames.elementAt(i);
fds = new FileDataSource(currentFileName);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
// create the Multipart and its parts to it
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
msg.setHeader("X-Mailer",MAILER);
// set the Date: header
msg.setSentDate(new Date());
// send the message
line 180 Transport.send(msg);Yes. All the third party jar files and our application jar are put on the server side. Here is the JNLP file:
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for software-->
<jnlp spec="1.0+" codebase="http://www.software.com/apps" href="client.JNLP">
<information>
<title>client application</title>
<vendor> * </vendor>
<homepage href="docs/help.html"/>
<description>Client</description>
<description kind="short">A tool</description>
<icon href="images/logo.jpg"/>
<offline-allowed/>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.3"/>
<jar href="lib/client.jar"/>
<jar href="lib/mail.jar"/>
<jar href="lib/smtp.jar"/>
<jar href="lib/activation.jar"/>
</resources>
<application-desc main-class="com.software.client.MainFrame">
<argument>2226</argument>
<argument>www.software.com</argument>
<argument>5351</argument>
</application>
</jnlp> -
How to send Secured Mail using Java Mail?
I want to send mails with "Send Secure" option using Java Mail. Now mails are being sent using Java Mail connecting to smtp host.
Appreciating your help.
Thanks.There are third party libraries to help with this. Bouncy Castle is very popular.
See the [JavaMail Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] page. -
How to send HTML Format Mail using Java Mail in oracle 9i Forms
Dear All
could you please tell me how to send HTML Format Mail using Java Mail in oracle 9i Forms and how to implement the java mail ?
if it is possible, could you please send me the sample code? please very urgent
Thanks
P.SivaramanHello,
<p>Here is a Form sample.</p>
Francois -
Using Java Mail with lotus notes
we are using lotus notes as default mail client and lotus notes server , there is no pop3 or smtp server as far as the intranet mailing goes,
i am developing an application in which i have a form which the users will fill in if they forget their logging in passwords, as soon as they submit the form they will get an autogenerated email which will send them their passwords. considering the above scenario can i use java mail api for thisNo. If you aren't running the pop3 or smtp services then the Java mail API won't help you at all, unless there is a SMTP server somewhere that you can use to deliver mail to your Notes server. If you use Notes for external emails there must be a server somewhere!!??
You can use the Notes Java API to create and send a document if you have the DIIOP service running on the Notes server.
SH -
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 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 Read An Attachment Using Java Mail
Hi
I Am Able To Read The Mail Using Java Mail ,but Unable To Read The Attachment Which Comes Along With The Mail.
Please Help Me , In Reading The Attachment.Hi
I Am Able To Read The Mail Using Java Mail ,but
t Unable To Read The Attachment Which Comes Along
With The Mail.
Please Help Me , In Reading The Attachment.Do you mean:
- I only recieve .txt or .doc attachments and I want to see the contents? Or could you get a .jpg as well?
or
- Do you need to seperate the attachment from the e-mail and then view it?
Maybe you are looking for
-
Mandatory fields for BAPI_ACC_DOCUMENT_POST
Hi I am getting the follwing data from the file (Which is coming from oracle) invoice number and the amount, from that i have to use Fb70 tcode for posting ,Please help me what are the mandatory fields for FB70, how will get those fields from SAP. Ho
-
Limiting output to 10 per page (servlets)
I'm using netBeans to create a servlet that querys the database and displays the results. I'm trying to limit the results to 10 per a page but I'm having trouble. I've referred to Karl Moss's guide to java servlets and attempted to input his coding,
-
Quantity does not show in stock
HI I have done some purchase order and goods receipt based on the PO for the items. the items i received was less than what is in the P.O which i have done in the GRPO document. But when i checked the quantity in stock it was less than what i had rec
-
Does WET200 support WPA-Enterprise/TKIP?
I could not connect a WET200 (newly bought) to our WPA-enterprise/TKIP wireless network. Can anyone tell me what was wrong? Does WET200 support WPA-enterprise? Please help! Thanks a lot.
-
How do I get a purchased ring tone from my iPad to my iPhone?
I purchased a new ring tone and wasn't thinking. I downloaded it to my iPad instead of my iPhone. I don't know how to transfer it from the iPad to my iPhone.