JavaMail Gmail Exception when reading mails
I am using JavaMail for reading messages in a gmail account.
My general problem is validationException. My code is the following.
public class MessagesReader {
public static String usage = "Usage: java gmailTest user password subject";
public static void main(String[] args) {
String username = "username";
String password = "password";
Properties pop3Props = new Properties();
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
pop3Props.setProperty("mail.pop3.user", username);
pop3Props.setProperty("mail.pop3.passwd", password);
pop3Props.setProperty("mail.pop3.ssl", "true");
pop3Props.setProperty("mail.pop3.host", "pop.gmail.com");
try {
checkForMessage(pop3Props, null);
} catch (Exception e) {
e.printStackTrace();
public static void checkForMessage(Properties props, String msgSubject)
throws NoSuchProviderException, MessagingException {
Session session = null;
Store store = null;
String user = ((props.getProperty("mail.pop3.user") != null) ? props
.getProperty("mail.pop3.user") : props.getProperty("mail.user"));
String passwd = ((props.getProperty("mail.pop3.passwd") != null) ? props
.getProperty("mail.pop3.passwd")
: props.getProperty("mail.passwd"));
String host = ((props.getProperty("mail.pop3.host") != null) ? props
.getProperty("mail.pop3.host") : props.getProperty("mail.host"));
if ((props.getProperty("mail.pop3.ssl") != null)
&& (props.getProperty("mail.pop3.ssl").equalsIgnoreCase("true"))) {
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//Replace socket factory
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
// configure the appropriate properties so JavaMail doesn't
// fall back to an unsecure connection when a secure one fails:
props.setProperty("mail.pop3.socketFactory.fallback", "false");
String portStr = ((props.getProperty("mail.pop3.port") != null) ? props
.getProperty("mail.pop3.port")
: "995");
//change the default port number to the corresponding port that your protocol's secure version uses;
//otherwise, you must use a fully qualified address (that includes a port number) in the URL passed
//to JavaMail (for example, imap://id:[email protected]:993/folder/), or else you get an
//"unrecognized SSL handshake" exception. You specify these properties like so:
props.setProperty("mail.pop3.port", portStr);
props.setProperty("mail.pop3.socketFactory.port", portStr);
URLName url = new URLName("pop3://" + user + ":" + passwd + "@"
+ host + ":" + portStr);
session = Session.getInstance(props, null);
store = new POP3SSLStore(session, url);
//Unfortunately, you may realize that the code above throws an SSLException "untrusted server cert chain"
//if the mail server certificate is not installed locally. In that case, you should obtain a correct,
//valid certificate for the server and use the keytool utility to add it to a local key storage at
//<javahome>\jre\lib\security\cacerts.
} else {
session = Session.getInstance(props, null);
store = session.getStore("pop3");
session.setDebug(true);
store.connect(host, user, passwd);
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message[] allMsgs = folder.getMessages();
for (int i = 0; i < allMsgs.length; i++) {
System.out.println(allMsgs.getSubject());
folder.close(true);
store.close();
When I execute the above code I get the following exception:
[java] DEBUG: setDebug: JavaMail version 1.4ea
[java] DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL true
[java] javax.mail.MessagingException: Connect failed;
[java] nested exception is:
[java] javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
[java] at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
[java] at javax.mail.Service.connect(Service.java:275)
[java] at javax.mail.Service.connect(Service.java:156)
[java] at javamail.MessagesReader.checkForMessage(Unknown Source)
[java] at javamail.MessagesReader.main(Unknown Source)
[java] Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
[java] at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.AppInputStream.read(DashoA6275)
[java] at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
[java] at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
[java] at java.io.DataInputStream.readLine(DataInputStream.java:562)
[java] at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:347)
[java] at com.sun.mail.pop3.Protocol.<init>(Protocol.java:91)
[java] at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
[java] at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
[java] ... 4 more
[java] Caused by: sun.security.validator.ValidatorException: No trusted certificate found
[java] at sun.security.validator.SimpleValidator.buildTrustedChain(SimpleValidator.java:304)
[java] at sun.security.validator.SimpleValidator.engineValidate(SimpleValidator.java:107)
[java] at sun.security.validator.Validator.validate(Validator.java:202)
[java] at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6275)
[java] at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6275)From all the relative posts I have understood that the problem is associated with an SSL certificate. I have the gmail certificate. Taken from the padlock of the gmail browser page and so I have a gmail.cer.
I know that I have to use a keytool to do something that I have not understand.
Can you please give me some instructions?
Or the forementioned exception has any other solution??
Thanking you in advance
Ok here.. im using this code to read from gmail too....
* MailSender.java
* Created on 14 November 2006, 17:07
* This class is used to send mails to other users
package jmailer;
* @author Abubakar Gurnah
import java.sql.SQLException;
import java.util.*;
import java.io.*;
import java.sql.ResultSet;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.InternetAddress;
/* Monitors given mailbox for new mail */
class MessageRead implements Runnable{
private String status;
private String uname;
private boolean serverStatus=true;
private String serverConn;
private int freq;
private String account;
private DbConn db;
private ResultSet rsA;
private Properties props;
private Session session;
private Store store;
private Folder folder;
* @param account get the thread account name
* @param uname logged in user name
* @param mailServer pop3 mail server
* @param mailuname pop3 account username e.g [email protected]
* @param mailPwd pop3 account password
* @param port pop3 access port
* @param SSL pop3 support encryption?
* @param freq the frequency that the server will check for a new message
public MessageRead(String account,String uname,String mailServer,String mailuname,
String mailPwd,String port,String SSL,int freq){
this.uname=uname;
this.freq=freq;
this.account=account;
db=new DbConn();
rsA=db.executeQuery("SELECT * " +
"FROM Accounts " +
"WHERE AccountName='" + uname + "'");
connectToServer(uname,mailServer,mailuname,
mailPwd,port,SSL);
* @param b set the thread on/off
public void setStatus(boolean b){
serverStatus=b;
* @return if the server is on/off
public boolean getStatus(){
return serverStatus;
* @param uname logged in user name
* @param mailServer pop3 mail server
* @param mailuname pop3 account username e.g [email protected]
* @param mailPwd pop3 account password
* @param port pop3 access port
* @param SSL pop3 support encryption?
public void connectToServer(String uname,String mailServer,String mailuname,
String mailPwd,String port,String SSL){
serverConn=mailServer+":"+mailuname;
try {
if(SSL.equalsIgnoreCase("true")){
Properties props = System.getProperties();
props.setProperty( "mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty( "mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", port);
props.setProperty("mail.pop3.socketFactory.port", port);
Session session = Session.getInstance(props);
store = session.getStore("pop3");
}else{
props=new Properties();
props = System.getProperties();
// Get a Session object
session = Session.getInstance(props, null);
store = session.getStore("imap");
// session.setDebug(true);
// Get a Store object
// Connect
store.connect(mailServer, mailuname, mailPwd);
// Open a Folder
folder = store.getFolder("INBOX");
System.out.println("Opening the inbox folder for " + mailServer);
if (folder == null || !folder.exists()) {
//Tray.showBallon("Warning","Invalid folder Name:"+folder.getName(),Tray.WARNING);
System.exit(1);
folder.open(Folder.READ_WRITE);
// Add messageCountListener to listen for new messages
folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
System.out.println("new mail " + serverConn);
readMail(ev);
// Check mail once in "freq" MILLIseconds
} catch (Exception ex) {
ex.printStackTrace();
* Listen for incoming messages
public void run(){
try {
while(serverStatus){
// sleep for freq milliseconds
// This is to force the IMAP server to send us
// EXISTS notifications.
System.out.println("Reading for change for " + serverConn);
folder.getMessageCount();
Thread.sleep(freq);
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (MessagingException ex) {
ex.printStackTrace();
* This method is triggered upon receival of the message
* @param ev Message Object event
public void readMail(MessageCountEvent ev){
Message[] msgs = ev.getMessages();
String from="";
String subject="";
String body="";
status="New Mail";
// Message retrival part
for (int i = 0; i < msgs.length; i++) { // for each new entry
try {
from=((InternetAddress)msgs.getFrom()[0]).getPersonal(); //get From whom the came from
if (from==null)
from=((InternetAddress)msgs[i].getFrom()[0]).getAddress();
subject=msgs[i].getSubject(); //get the subject of the message
//check message if it contain other parts, such as attachment
Part messagePart = msgs[i];
Object content=messagePart.getContent();
if (content instanceof Multipart){
messagePart=((Multipart)content).getBodyPart(0);
// -- Get the content type --
String contentType=messagePart.getContentType();
//this the mail is plain mail.. or contain some html
if (contentType.startsWith("text/plain")|| contentType.startsWith("text/html")){
//get the mail
BufferedReader reader=new BufferedReader(new InputStreamReader(messagePart.getInputStream()));
//start reading line after line
String b=reader.readLine();
while (b!=null){
b=reader.readLine();
body+=b + "\n";
writingLogs(from + ":" + ((InternetAddress)msgs[i].getFrom()[0]).getAddress(),subject,body);
checkMsg(((InternetAddress)msgs[i].getFrom()[0]).getAddress(),subject,body);
msgs[i].setFlag(Flags.Flag.DELETED, true); //delete the messages
reader.close();
} catch (IOException ioex) {
ioex.printStackTrace();
} catch (MessagingException mex) {
mex.printStackTrace();
* This method is used to write the mail to the log, so as to keep track
* of all the incoming messages...
* @param strFrom from where the mail is originated
* @param strSubject the subject of the message
* @param strBody the body of the message
public void writingLogs(String strFrom,String strSubject,String strBody ){
Date today = new Date();
DateFormatSymbols symbols;
SimpleDateFormat formatter;
symbols = new DateFormatSymbols(new Locale("en","US"));
formatter = new SimpleDateFormat("yyyyMMddHHmmss", symbols);
String result = formatter.format(today);
BufferedWriter bw;
try {
String path=new File(".").getCanonicalPath();
bw = new BufferedWriter(new FileWriter(path+"\\logs\\"+result + ".txt"));
bw.write("From..." + strFrom +"\n");
bw.write("---------------------------------------------------------\n");
bw.write("Subject..."+strSubject+"\n");
bw.write("---------------------------------------------------------\n");
bw.write("Body..."+strBody+"\n");
bw.flush();
bw.close();
} catch (IOException ex) {
ex.printStackTrace();
public void checkMsg(String from,String subject,String body){
String msg="";
ResultSet rsP=db.executeQuery("SELECT * " +
"FROM priority " +
"WHERE uname='" + uname + "'");
try {
boolean fReading=true;
int i=1;
rsP.first();
while(fReading){
int p=checkPriority(rsP.getString("Priority"+(i++)));
if(i>3) {fReading=false;break;}
switch(p){
case 1:
msg=readFrom(from,body);break;
case 2:
msg=readSubject(from,subject,body);break;
case 3:
msg=readBody(from,body);break;
case -1:
fReading=false;break;
} catch (SQLException ex) {
ex.printStackTrace();
public int checkPriority(String p){
if (p.equalsIgnoreCase("From")){
return 1;
}else if(p.equalsIgnoreCase("Subject")){
return 2;
}else if(p.equalsIgnoreCase("Body")){
return 3;
return -1;
private String readBody(String from, String body) {
return null;
private String readSubject(String from, String subject, String body) {
return null;
private String readFrom(String from, String body) {
boolean Matched=false;
String s=from.substring(0,from.indexOf("@"));
ResultSet rsR=db.executeQuery("SELECT * " +
"FROM Rules " +
"WHERE [if]='from' and uname='" + uname + "'");
try {
rsR.first();
do{
Matched=checkPattern(from,rsR.getString("Contains"));
if(Matched){
break;
}while(rsR.next());
MailSender m=new MailSender();
m.send(rsA.getString("smtpmailuname"),
rsA.getString("smtpmailuname"),
rsA.getString("smtpserver"),
rsA.getString("smtpport"),
rsA.getString("smtpmailuname"),
rsR.getString("phoneNo"),
"Server Message",
body
} catch (SQLException ex) {
ex.printStackTrace();
return null;
public boolean checkPattern(String original, String contains){
if(contains.indexOf(original)>0){
return true;
return false;
Let me explain... just consider connectToServer
there is SSL.equalsIgnoreCase("true") which is google.. this is what you want in this if statement... it configure the properties of google... try it..
Similar Messages
-
How to close sidebar when reading mail
when reading mail in iPad i am unable to close the sidebar which shows emails accounts and inbox.
This is to "art3410" --
That's exactly how it was designed to work. If you want to suggest a different method to Apple, then do so here ...
Product Feedback
https://www.apple.com/feedback/ -
Authentication Failed Exception while reading mail using POP
Hi,
I am using POP3 for reading mails from mail id. When I try to read the mail from Microsoft Exchange server 2007, it is a success. But same code is giving "Authentication Failed Exception" with Microsoft Exchange server 2010.
One more difference, I figured out. Microsoft Exchange server 2007 is having NTLM as LoginType and code works fine with it. Where as Microsoft Exchange server 2010 is having TLS as LoginType and code is giving "Authentication Failed Exception".
Line of code which is giving exception is...
store = session.getStore(providerPOP3);
store.connect(host, user, password); //throws exception
Please advice how this code can work with Microsoft Exchange server 2010 having TLS as LoginType.
Regards,Thanks for your reply.
Yes, I am using javamail 1.4.3. My code is working fine with Exchange server 2007 having NTLM.
But when I changed the credentials as per mail id configured on Exchange Server 2010 having TLS support, it did not work. Can you please help what code change would be required to read mails from mail id configured on Exchage Server 2010 having TLS support.
Sorry, if my point seems not understandable as I am as new with these terminologies (mail server and all) as baby with world. :)
Thanks for supprt. -
Odd gmail behaviour when using mail.app
Hello there,
Ever since upgrading to Mavericks, I've been experiencing odd behaviour when sending messages from my gmail account in mail.app. I send a message and up to ten copies of the message appear in mail.app's trash.
Does anyone know what might be the cause of this?
many thanks,
Chidithis is a setting in gmail that interfer with mail.app
the setting is that mail.app is that when you type a mail it will auto save it while you are typing. and gmail will delete the saved onece and the mail.app will create a new all the time
duno how to turn this off, try by rebuilding the mailbox in mail.app -
Exception when sending mail to client on a different mail server
Hi,
When i try to send a mail to a client on a different mail server from mine I am getting the following exception.
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 not local host yahoo.com, not a gateway
It works perfectly fine when i send a mail to a client on my mail server. I am stuck up at this point - PLEASE HELP, any help greatly appreciated.
Thank you,
npailaMost of these are, of course, anti-Spam measures implemented by the various SMTP hosts, to prevent spammers from using their servers to spread the stuff (what you're doing is exactly what Spammers do as well).
In general, most properly configured SMTP servers will only accept messages if:
(a) Your IP address (as seen by that SMTP server) maps back to a proper host name, AND
(b) The recipient of the message is "local" as determined by that SMTP server, AND
(c) In many cases, the SMTP server will also cross-check your HELO/EHLO address and the MAIL FROM: value.
It may take a few attempts to get all this right. -
Exception Access Denied (java.io.filepermission temp read) is return when I try to run an applet that uses JAI and the JRE is 1.5.x
Everything works well in the 1.3.x world.
My applet is signed by Thwate and I want to able to distribute my applet without telling every user to modify the java.policy file.
Is there any work around for this problem?
Any help would be greatly appreciated.
Thanks AllenWhen file is read your main bpel process doesn't come in the picture, it is done via File adapter. If adapter fails to read, you can call second bpel process (rejection handler, which implements specific interface and reads as opaque).
In nut-shell, you will need one more proccess, but that can be genaric and shared across the enterprise.
Regards,
Chintan -
Unhandled SOAP Exception When Reading from an External List created from SQL Server
This is absolutely doing my head it. Doesn't matter what I do, which approach I take or how its done, I gt the same crappy error from Sharepoint Designer 2010.
Pulling Data from SQL Server 2008 using An external List. All I want to do is read the data and display in on the Sharepoint Site.. Nothing fancy, just read.
Created a Limit filter to limit 100 records per time, removed any primary keys, get no warnings or Errors upon creating the External List or View.
But when I add it to the view or data source in page designer, I get the unhandled exception error we all know and love :-(...
Anybody shed any light on this before I make a dell 2900 Server sized hole in my window?
Sharepoint Foundation 2010
Sharepoint Designer 2010
SQL Server 2008
TaHi,
If want to change the WCF client (BCS in this case) timeout, you need to change the registry on the SharePoint server.
The keys are located under:
HKEY_CURRENT_USER\Software\Policies\Microsoft\office\15.0\Common\Business Data.
Moreinformation:
http://blogs.technet.com/b/meamcs/archive/2010/12/23/configuring-wcf-connection-timeout-for-bcs.aspx
Best Regards
Dennis Guo
TechNet Community Support -
C# windows store app exception when reading text
Guys
I keep getting a the exception 'System.ArgumentOutOfRangeException' with he following line of code
var Lines = await Windows.Storage.FileIO.ReadTextAsync(file);
I presume its because there is a limit to how much text can be read into the string Lines as it worked ok untill i added more text to the file once it is read into the string I then use split to put each line into an array
The file is a text file and its is made up of 500+ lines of text which will grow to about 3000 so I need a way of reading these
I need to store each line in an array
This is he code I use at the moment
string filepath = @"Assets\DATA.csv";
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await folder.GetFileAsync(filepath); // error here
var Lines = await Windows.Storage.FileIO.ReadTextAsync(file);
string[] lines2 = Lines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
It reads the file from the assets directory into a string and then splits it to an arrayis the a way of reading each line and putting it directly into an arrayEach line is terminated by a newlineAny help appreciatedMarkSince you're splitting into lines anyway, Does
FileIO.ReadLinesAsync work for you any better?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined
objects and unknown namespaces. -
Since upgrading to 10.9.x, I have been having issues with OSX Mail application such that it is not marking emails as read when I have done so in Gmail website.
Example:
1). Received a new email in my Gmail account
2). In mail.google.com, the email is shown as "New"
3). In the Apple Mail application in my MacBook Air (MBA), the email is shown as "New"
4). In mail.google.com, I opened the email, which is now marked as read (NOT new)
5). In the Apple Mail application, the email is STILL shown as "New".
I have tried syncing the Mail app, pressing "Go Offline", and leaving the Mail app open for hours, but no go.
HOWEVER, if after step #4 above, I CLOSE the Mail app and opened it again, the Mail app will detect the change and immediately marked the same email as read (NOT new).
It seems that the Mail app having trouble syncing with Gmail and marking read email as...well, read.
My configuration:
1). OSX 10.9.2
2). Three (3) Gmail accounts configured using IMAP
Anyone know the workaround to this?No one using Apple's own Mail program with Gmail?
-
Hi,
i need to read my inbox from my gmail account.
i have given the following configuration parameters in my program inside a hashtable.
Hashtable hashObj = new Hashtable();
hashObj.put("host","pop.gmail.com");
hashObj.put("user","[email protected]");
hashObj.put("pswd","password");but i am getting the following error::
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at ReadEmailClient.ReadEmail(ReadEmailClient.java:35)
at ReadEmailClient.main(ReadEmailClient.java:83)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:81)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:201)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:144)
... 4 moreHello!
Did you already find why you received that exception when trying to connect to pop.gmail.com?
I'm having the same problem. I can ping pop.gmail.com but I can't telnet it using port 995 (as gmail sais) or port 110 (pop3 default port).
I guess it's not a problem of my code, right? I'm using code from the following link:
http://www.java-tips.org/other-api-tips/javamail/connecting-gmail-using-pop3-connection-with-ssl-2.html
Can you please give me some ideas to solve that.
Greetings,
Filipe -
Getting exceptions while sending mail using javamail api
Hi to all
I am developing an application of sending a mail using JavaMail api. My program is below:
quote:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class sms
public static void main(String args[])
try
String strstrsmtserver="smtp.bol.net.in";
String strto="[email protected]";
String strfrom="[email protected]";
String strsubject="Hello";
String bodytext="This is my first java mail program";
sms s=new sms();
s.send(strstrsmtserver,strto,strfrom,strsubject,bodytext);
catch(Exception e)
System.out.println("usage:java sms"+"strstrsmtpserver tosddress fromaddress subjecttext bodyText");
System.exit(0);
public void send(String strsmtpserver,String strto,String strfrom ,String strsubject,String bodytext)
try
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties p=new Properties(System.getProperties());
if(strsmtpserver!=null)
p.put("mail.transport.protocol","smtp");
p.put("mail.smtp.host","[email protected]");
p.put("mail.smtp.port","25");
Session session=Session.getDefaultInstance(p);
Message msg=new MimeMessage(session);
Transport trans = session.getTransport("smtp");
trans.connect("smtp.bol.net.in","[email protected]","1234563757");
msg.setFrom(new InternetAddress(strfrom));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(strto,false));
msg.setSubject(strsubject);
msg.setText(bodytext);
msg.setHeader("X-Mailer","mtnlmail");
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println("Message sent OK.");
catch(Exception ex)
System.out.println("here is error");
ex.printStackTrace();
It compiles fine but showing exceptions at run time.Please help me to remove these exceptions.I am new to this JavaMail and it is my first program of javamail.Please also tell me how to use smtp server.I am using MTNL 's internet connection having smtp.bol.net.in server.
exceptions are:
Here is exception
quote:
Javax.mail.MessagingException:Could not connect to SMTP host : smtp.bol.net.in, port :25;
Nested exception is :
Java.net.ConnectException:Connection refused: connect
At com.sun.mail.smtp.SMTPTransport.openServer<SMTPTransport.java:1227>
At com.sun.mail.smtp.SMTPTransport.protocolConnect<SMTPTransport.java:322>
At javax.mail.Service .connect(Service.java:236>
At javax.mail.Service.connect<Service.java:137>
At sms.send<sms.java:77>
At sms.main<sms.java:24>Did you find the JavaMail FAQ?
You should talk to your ISP to get the details for connecting to your server.
In this case I suspect your server wants you to make the connection on the
secure port. The FAQ has examples of how to do this for GMail and Yahoo
mail, which work similarly. By changing the host name, these same examples
will likely work for you. -
I use a gmail account for my mail. When I send an email I sometimes get multiple duplicates (up to 10-12) of the same sent message saved in my sent file. help
Did you check your user name and password in Settings>Mail,Contacts,Calendars...tap your email account, tap SMTP, then tap the primary server name. Make sure the settings there are correct.
-
Hello,
I had no problem accessing my Gmail account through the mail icon until two weeks ago. I can still access my Gmail account through Safari, but when I attempt to access my Gmail through the mail icon, Gmail tells me that my password is invalid. Any Suggestions? Any help would be greatly aprecieated.
Thanks,
FrankI see you are using LastPass. Could that add-on be interfering with your login?? You could try disabling it temporarily under Tools > Add-ons to test that theory.
-
Exception in java mail API when parsing email
I am receiving the following exception when receiving some emails that contain attachments with java mail (irrelevant part of stack trace omitted):
javax.mail.internet.ParseException: Expected ';', got ","
at javax.mail.internet.ParameterList.<init>(ParameterList.java:289)
at javax.mail.internet.ContentDisposition.<init>(ContentDisposition.java:100)
at javax.mail.internet.MimeBodyPart.getFileName(MimeBodyPart.java:1136)
The header of a message the causes the problem is:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) ------------ Message headers ------------
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from mail2.uscourts.gov ([10.170.250.2])
by ushub06.uscmail.dcn (Lotus Domino Release 8.5.2FP1 HF3)
with SMTP id 2011042514392620-733724 ;
Mon, 25 Apr 2011 14:39:26 -0400
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from (unknown [63.174.91.123]) by avms-usc-04c-02vh.ibmta.uscourts.gov with smtp
id 191c_067d_57fad3b8_6f6b_11e0_8de9_00265519f638;
Mon, 25 Apr 2011 18:39:24 +0000
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-WSS-ID: 0LK815L-05-67D-02
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-M-MSG:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from kcmexclaim.Our-Firm.com (unknown [10.42.5.222])by mail4.stinson.com (Axway MailGate 3.8.1) with ESMTP id 27239A12C1D; Mon, 25 Apr 2011 13:39:20 -0500 (CDT)
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from KCME2K7-HUB02.Our-Firm.com ([10.42.5.19]) by kcmexclaim.Our-Firm.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 25 Apr 2011 13:39:23 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Received: from FIRMCMS01.Our-Firm.com ([fe80::81d0:dd2b:9983:1126]) by KCME2K7-HUB02.Our-Firm.com ([::1]) with mapi; Mon, 25 Apr 2011 13:39:22 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) From:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) To:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Cc:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Disposition-Notification-To:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Date: Mon, 25 Apr 2011 13:39:21 -0500
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Subject: Order Regarding Application To Employ SMH as Debtor's Counsel
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Thread-Topic: Order Regarding Application To Employ SMH as Debtor's Counsel
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Thread-Index: AcwDb/bpRQlxt/eTQC6BA7G10hdWJQAB99vQ
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Message-ID: <[email protected]>
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Accept-Language: en-US
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-MS-Has-Attach: yes
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) X-MS-TNEF-Correlator:
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) acceptlanguage: en-US
2011-04-25 14:39:48,060 INFO [STDOUT] (WorkManager(2)-97) Importance: Normal
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Priority: normal
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4841
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) MIME-Version: 1.0
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Return-Path:
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-OriginalArrivalTime: 25 Apr 2011 18:39:23.0526 (UTC) FILETIME=[18E10260:01CC0378]
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) X-MIMETrack: Itemize by SMTP Server on USHUB06/H/US/USCOURTS(Release 8.5.2FP1 HF3|December 21, 2010) at 04/25/2011 02:39:26 PM, Serialize by POP3 Server(Release 8.0.2FP3 HF28|December 28, 2009) at 04/25/2011 02:39:47 PM
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Transfer-Encoding: 7bit
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Class: urn:content-classes:message 2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Type: multipart/mixed; boundary="_004_52835C1F7A6C8D4F989C433DCC611CA06F252D6682FIRMCMS01OurF_"
2011-04-25 14:39:48,061 INFO [STDOUT] (WorkManager(2)-97) Content-Language: en-US
the client/OS combination of the mail sender is Windows XP service Pack 3/Outlook 2007 , Java Mail version 1.4.3
Any help would be appreciated
Edited by: 854778 on Apr 26, 2011 8:28 AMThe exception is occurring when parsing the Content-Disposition header.
I don't see that header in the list of headers you provided.
Can you save the entire message to a text file using
msg.writeTo(new FileOutputStream("msg.txt"));
Then look for the Content-Disposition header in msg.txt. Most likely you'll
find that it is incorrectly formatted - as the exception says, there's a comma
in a place that a semicolon is expected. -
I have 2 email accounts Gmail and Bell mail. I can add mailboxes to gmail but when I try the same procedure with Bell mail I don't get an edit button so can't add any mailboxes.
Mailboxes can be added only to IMAP accounts. Is Bell setup as IMPAP or POP?
Maybe you are looking for
-
While processing a message : Error HTTP 404: not found
Hi gurus, I'm stuck on a File-XI-IDoc scenario. Here is the message i get in the Message Tool Display: Erreur lors de la transmission du message au point d'accès http://rchase12:53000/sap/xi/engine?type=entry via la connexion File_http://sap.com/xi/X
-
Java 6 Update 12 64bit Java Webstart documentation
I notice that 64bit 6 Update 12 comes with 64bit version of Java Webstart - I am just wondering whether there are any documentation on how 64bit Java Webstart works? For example: 1) By default it will use the 64bit JRE to launch an application. What
-
I deleted "preview" by an accident. how do i get it back?
i deleted "preview" by an accident. how do i get it back? i deleted it completly off of my computer, so its not eve in the trash.
-
Error while executing through Metadata Navigator.
Hi all, i am getting the below error when i tried to run a scenario from metadata navigator. please let me know what is wrong. java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:368) at java.math.BigDecimal.<init>(BigDecim
-
I have a png created thusly: In FW - Simple rectangle of solid color, with transparency slider set it to 65% opaque. In Optimize panel set: png8, AlphaTransparency, Web Adaptive, Colors 256. Then Export it. This produces a nice semitransparent image