Java Mail Server
Is there a way to write a POP and SMTP server with java?
Java? Yes, and several people have done so. See the [JavaMail FAQ|http://java.sun.com/products/javamail/FAQ.html] and [Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] list.
JavaMail? Only sort of.
[http://java.sun.com/products/javamail/FAQ.html#javamailserver|http://java.sun.com/products/javamail/FAQ.html#javamailserver]
Similar Messages
-
Java newbie wants to set up a java mail server
hi
i want to set up a java mail server... but I don't really know how
I've installed tomcat-apache and a mail server but I don't know how to implement the java part...
here's an example that i refer to: http://java.sun.com/developer/technicalArticles/javaserverpages/emailapps/
any step by step guide for beginner like me?
thanx a lot
byehttp://james.apache.org/
-
I would really appreciate any help or support from the forum on the
follwing queries.
I am presently developing an application using the James Mail Server,
however after initially setting it up to recieve mail on a local machine
using pop3, I am not able to find any documentation on it's support for
creating other folders like a 'sent' or even 'trash folder'.
[II]
If it is possible to create other folders in James i.e. a 'trash' folder,
how would one delete mail so as to:
(a)Relocate the message from an inbox folder to another folder i.e.
'trash' folder and
(b) completely delete it from the server?Get rid of the j2ee jar file.
-
Can java mail be used for distributed exchange server?
H,
I am trying to connect to MS Exchange Server to read my mails using Java Mail API.
I have a questions about using it with Exchange server.
We have 6-7 exchange servers in our company and different users have mailboxes on different servers. My internet mail application will be used by everybody in the company.
But while connecting to exchange server using java mail I can only cnnnect to one server and port. What happens when user mailbox is not on that server. How can I use javamail in this scenario where user mailboxes are on separate servers??
Thanks
[email protected]You said that you can connect to Exchange server my you help me with this because i cant connect to Exchange server, mayby you can post me a code example? Thanks
-
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 -
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 -
Free SMTP server for Java mail testing
Hi all,
Are there any free SMTP servers that can be downloaded from the Net for Java mail. Thanks.
Regards
RamI am sorry ..may be my question was not very clear. I do not have am SMTP host. I need an SMTP host to route emails...is that possible.
If I have an SMTP host on my machine, then it will act as a router to route messages to other email severs like yahoo or hotmail.
So the "from" will be a user from the SMTP host.i.e my machine user and the "to" will be some email "[email protected]" or "[email protected]".
Is it posssible to route emails directly to any Yahoo or hotmail server using just java mail client?
Thanks
Regards
RP -
Is there any technique to ask Java to connect to mail server?
The Problem is: I would like to use Java Technique to create some mail account on one mail server!
You can use the JavaMail api to send and receive email but not for creating accounts... AFAIK creating a mail account is not standardized in any RFC and depends very much on your mail server.
-
How will I send mail to Yahoo mail id using java Mail api. I have used smtp.mail.yahoo.com as smtp server. Remember that I should not use my password.
If possible reply to mail id.
[email protected]
Thanks in advance.Try this code:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class AttachExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String to = args[2];
String filename = args[3];
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
// Get session
Session session = Session.getInstance(props, null);
// Define message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail Attachment");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Here's the file");
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
// Create second body part
messageBodyPart = new MimeBodyPart();
// Get the attachment
DataSource source = new FileDataSource(filename);
// Set the data handler to the attachment
messageBodyPart.setDataHandler(new DataHandler(source));
// Set the filename
messageBodyPart.setFileName(filename);
// Add part two
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport transport = session.getTransport("smtp");
transport.send(message);
When running the program type this line:
java AttachExample smtp.mail.yahoo.com email_address_from email_address_to filename
Be sure to turn your yahoo account to pop messages other than the browser.Just go to Options & click on the pop accounts & set it.
Take care -
Java Mail,SMTP server not starting,help required urgently
Hi i have been working on java mail .Yesterday it was working ok but today suddenely i am getting this thing.its not starting the smtp server i guess,just exiting and get the command prompt ..dont know what to do.help required how to go about this error
am pasting the debug information.please check and let me know
the compilation ,smtp server and others are all valid
thanks
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Pavan>cd C:\Program Files\Java\jdk1.5.0_07\bin
C:\Program Files\Java\jdk1.5.0_07\bin>javac jdbcExample3.java
C:\Program Files\Java\jdk1.5.0_07\bin>java jdbcExample3 smtpserver address
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_07\jre\lib\
javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax
.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsyste
ms, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com
.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLSt
ore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsyst
ems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.su
n.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=jav
ax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc],
com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP
3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.
sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STOR
E,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Prov
ider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc],
pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems
, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun
Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.S
MTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_07\jre\lib\
javamail.address.map (The system cannot find the file specified)
C:\Program Files\Java\jdk1.5.0_07\bin>The debug output doesn't show an obvious problem. You're
going to have to actually debug your program. A debugger
might be helpful. -
Java mail(fetch default SMTP server address)
I am writting a code to send an email using Java Mail API.
I have manged what I wanted(send a mail with an attachment)
But in my code I have hard coded the SMTP server address,that is what I dont want to do .Is there anything in java which can fetch the default SMTP server address ?Let me send the code itself to make it clear
Here the host is hard coded to10.1.1.5
I dont want that ,rather I would like my code itself to fetch the host
package javamail;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendMailUsage {
public static void main(String[] args) {
// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "[email protected]";
String from = "[email protected]";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "10.1.1.5";
// Create properties for the Session
Properties props = new Properties();
// If using static Transport.send(),
// need to specify the mail server here
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
// Get a session
Session session = Session.getInstance(props);
try {
// Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");
// Connect only once here
// Transport.send() disconnects after each send
// Usually, no username and password is required for SMTP
bus.connect();
//bus.connect("smtpserver.yourisp.net", "username", "password");
// Instantiate a message
Message msg = new MimeMessage(session);
// Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
// Parse a comma-separated list of email addresses. Be strict.
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(to, true));
// Parse comma/space-separated list. Cut some slack.
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(to, false));
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());
// Set message content and send
setTextContent(msg);
msg.saveChanges();
bus.sendMessage(msg, address);
setMultipartContent(msg);
msg.saveChanges();
bus.sendMessage(msg, address);
setFileAsAttachment(msg, "D:/ketan.txt");
msg.saveChanges();
bus.sendMessage(msg, address);
setHTMLContent(msg);
msg.saveChanges();
bus.sendMessage(msg, address);
bus.close();
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
// How to access nested exceptions
while (mex.getNextException() != null) {
// Get next exception in chain
Exception ex = mex.getNextException();
ex.printStackTrace();
if (!(ex instanceof MessagingException)) break;
else mex = (MessagingException)ex;
// A simple, single-part text/plain e-mail.
public static void setTextContent(Message msg) throws MessagingException {
// Set message content
String mytxt = "This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.";
msg.setText(mytxt);
// Alternate form
msg.setContent(mytxt, "text/plain");
// A simple multipart/mixed e-mail. Both body parts are text/plain.
public static void setMultipartContent(Message msg) throws MessagingException {
// Create and fill first part
MimeBodyPart p1 = new MimeBodyPart();
p1.setText("This is part one of a test multipart e-mail.");
// Create and fill second part
MimeBodyPart p2 = new MimeBodyPart();
// Here is how to set a charset on textual content
p2.setText("This is the second part", "us-ascii");
// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
mp.addBodyPart(p2);
// Set Multipart as the message's content
msg.setContent(mp);
// Set a file as an attachment. Uses JAF FileDataSource.
public static void setFileAsAttachment(Message msg, String filename)
throws MessagingException {
// Create and fill first part
MimeBodyPart p1 = new MimeBodyPart();
p1.setText("This is part one of a test multipart e-mail." +
"The second part is file as an attachment");
// Create second part
MimeBodyPart p2 = new MimeBodyPart();
// Put a file in the second part
FileDataSource fds = new FileDataSource(filename);
p2.setDataHandler(new DataHandler(fds));
p2.setFileName(fds.getName());
// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
mp.addBodyPart(p2);
// Set Multipart as the message's content
msg.setContent(mp);
// Set a single part html content.
// Sending data of any type is similar.
public static void setHTMLContent(Message msg) throws MessagingException {
String html = "<html><head><title>" +
msg.getSubject() +
"</title></head><body><h1>" +
msg.getSubject() +
"</h1><p>This is a test of sending an HTML e-mail" +
" through Java.</body></html>";
// HTMLDataSource is an inner class
msg.setDataHandler(new DataHandler(new HTMLDataSource(html)));
* Inner class to act as a JAF datasource to send HTML e-mail content
static class HTMLDataSource implements DataSource {
private String html;
public HTMLDataSource(String htmlString) {
html = htmlString;
// Return html string in an InputStream.
// A new stream must be returned each time.
public InputStream getInputStream() throws IOException {
if (html == null) throw new IOException("Null HTML");
return new ByteArrayInputStream(html.getBytes());
public OutputStream getOutputStream() throws IOException {
throw new IOException("This DataHandler cannot write HTML");
public String getContentType() {
return "text/html";
public String getName() {
return "JAF text/html dataSource to send e-mail only";
} //End of class -
Hi I am a novice, working on a mail sender though proxy. I read Java mail FAQ in http://java.sun.com/products/javamail/FAQ.html#proxy.
And also I found a snippet in below therad.
http://forums.sun.com/thread.jspa?threadID=615715&start=0&tstart=0
<QUOTE>here is the solution that you can send mail through a proxy server
Properties p = System.getProperties();
p.setProperty("proxySet","true");
p.setProperty("socksProxyHost","192.168.155.1");
p.setProperty("socksProxyPort","1080");</QUOTE>
I installed CCProxy in my machine and gave my own IP address ( 1. LAN IP and 2. IP from whatismyip.com; both works ) and port number. It works. But I gave IP addrss of my friend ( 1. LAN IP and 2. IP from whatismyip.com; both NONE work ) who got CCProxy and in his machine. But doesnt work ( throws Below exception).
Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.SocketException: Can't connect to SOCKS proxy:Connection timedout: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:310)
His IP address is found with whatismyip.com. I guess its a problem with IP address. What am I doing wrong here ?? Could some one help me out please ?
Edited by: baskark on Mar 8, 2009 6:26 PM
Edited by: baskark on Mar 8, 2009 6:44 PMI believe we can give some other socks proxy ip address too, other than CCproxy machine ip address If I am correct. Is there any specific way to use the socks server ip address ( such as provided in many websites, used for open relay) ? I tried some of them, which I am able to ping. But still I get the same exception like connection request timed out.
-
How to build a mail server in java?
greetings all i have an app(spring+hibernate) that needs to send thousands of emails simultaneously and i was told that the best solution here is to have a mail server i don't have any idea where to start or if there's a framework or a service that is better so please guys give me some info where to start, thank you.
[http://java.sun.com/products/javamail/FAQ.html#servers|http://java.sun.com/products/javamail/FAQ.html#servers]
-
Java mail api - sending mails to gmail account
Hello
I am using java mail api to send mails.when i send mails to gmail from ids which are not in gmail friends list, most of the mails are going to spam.Ofcourse, some of them go to inbox.I tried in lot of ways to analyse the problem.But nothing could help. Can anyone plzz tell me how to avoid mails going to spam in gmail, using java mail api?
Thank you in advance,
Regards,
Aradhana
Message was edited by:
Aradhanaam using the below code.
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth", isAuth);
Authenticator auth = new UserAuthenticator();
// Get session
Session s = Session.getDefaultInstance(props,auth);
// Define message
Message m = new MimeMessage(s);
// setting message attributes
try {
m.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
InternetAddress f_addr=new InternetAddress(from);
f_addr.setPersonal(personalName);
m.setFrom(f_addr);
m.setSubject(subject);
m.setSentDate(new Date());
m.setContent(msg,"text/plain");
m.saveChanges();
// send message
Transport.send(m);
Message was edited by:
Aradhana -
Error: The e-mail server could not be reached when the system was trying to
Dear All,
I've configured the Mail Transport in Portal successfully with SMTP as MS Exchange Server and Third-party Mailing servers. But due to some licensing issues a new MS Exchange mail server have been setup replacing the existing ones.
And when i configure the Mail Transport in the system i get the below message on the eMail Window:
"Error: The e-mail server could not be reached when the system was trying to send the message!
javax.mail.MessaginException: 530 5.7.1 Client ws not authenticated
I've configured (all the steps) the same way as i used to before and restarted the server as well! Please let me know the issue to be resolved, the telnet to the mailserver is also successful. I've try'd searching SDN, didn't find the exact solution... any notes on this?
Thanks,
MSHi,
It will depend on your infrastructure, I am not sure and have limited knowledge on netowrks, but in my current landscape both the system were in same domain, but still i had to maintain proxy configuration.
Since it giving authentication error, it feel it could be proxy error.
Please refer below links which talks about same error :
http://java.sun.com/products/javamail/FAQ.html#smtpauth
Or else i think it is issue with port.
Regards,
Jigar Oza
Edited by: jigar oza on Jul 6, 2010 12:43 PM
Maybe you are looking for
-
hi all I want to add an int object in the date object and wants to return date object I want to calculate the finishdate using startingdate and no.of days field which i am inputing from the user please help if anybody can
-
How to declare and use multi dimensional VARRAYs in PLSQL
Hi All, I am trying to create and use multidimensional varray in plsql code... can anyone let me know, how can I do this... Thanks Krishna
-
Hi Microsoft says the latest update for my Lumia is Denim why i cant get Denim ? Attachments: Cadsfsfpture.JPG 37 KB wp_ss_20150123_0001.png 42 KB wp_ss_20150123_0003.png 31 KB
-
So where is cover flow now then?
Because the new interface on iTunes 11 is beyond hideous!!! I can't believe you guys took such a backwards step... I absolutely HATE the new look. I've built up a library of nearly 15,000 songs on iTunes since around 2005, and tonight I feel like de
-
How to make a DFF segment mandatory only in one page?
Hi All, We have added a DFF in 2-3 pages. One of the segments in that DFF should be made mandatory only for one particular page. Is there any way to make it mandatory via personalization? I can't make it mandatory in DFF settings as it will make the