Hello, javax.mail.MessagingException: Unknown SMTP host:
Hello,
I am trying to send a mail and use a smtp Server which is located on the internet. I am however behind a firewall and am getting the following exception being thrown:
javax.mail.MessagingException: Unknown SMTP host:
This implies that I need to provide some settings for my proxy server. I though to solve this problem I could do the following:
System.getProperties().put("proxySet", "true");
System.getProperties().put("http.proxyHost", proxyHost);
System.getProperties().put("http.proxyPort", proxyport);
This however does not solve me problem as I still get the above exception. Could someone please give help me. Any suggestions,solutions or ideas as to what the problem might be would be appreciated.
Thanks much,
Alex.
HTTP is not SMTP.
Your proxy server no doubt allows your system to send
HTTP traffic to and from the outside world, and using
that code you posted would allow Java classes to do
that as well. But HTTP is not SMTP. Ask the network
people who configured your proxy server if it can act
as an SMTP proxy, and if so what you have to do to
use it in that way.Thanks much for your reply. I am however a little confused. Could you explain to me exactly what an SMTP proxy is/does.
Thanks much,
Alex.
Similar Messages
-
MessagingException "Unknown SMTP host"
Hi
I am using JavaMail to send out emails from an ecommerce application. We are now deploying the application and are getting the following message....
nested exception is:
class javax.mail.MessagingException: Unknown SMTP host: smtp.thehost.com ;
nested exception is:
java.net.UnknownHostException: smtp.thehost.com
(note the server name is not actually smtp.thehost.com) - ive used that one here for confidentality.
If i try to telnet to smtp.thehost.com on port 25 i get the expected 220 and everything seems fine. Its like JavaMail cant see the mailhost when everything else can.
I am using :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
on Redhat.
Any suggestions?
Regards
LawrenceIf i try to telnet to smtp.thehost.com on port 25 i get the expected 220 and everything seems fine. Its like JavaMail cant see the mailhost when everything else can.This suggests that you aren't telling JavaMail the right host name. It looks to me as if it has an unnecessary space at the end, but at any rate check your code.
-
Javax.servlet.ServletException: Unknown SMTP host
Hi
I am using tomcat and trying to send emails. I keep getting a javax.servlet.ServletException: Unknown SMTP host error.
I initially thought the problem was with the line: props.put("mail.smtp.host", "makethegrade.co.za"); But i checked the smtp info with the guys i'm hosing with and they said its right
I am currently setting the fields manually, so it can't be a problem with passing data around in the webpage
In my WEB-INF/lib i have jaf-1.0.2 and javamail-1.4.1 (i.e. mail.jar and activation.jar)
The code for my mailer bean is:
package mailer;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public final class MailerBean extends Object implements Serializable {
/* Bean Properties */
private String to = null;
private String from = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;
static {
/* Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "makethegrade.co.za");
session = Session.getDefaultInstance(props, null);
/* Setter Methods */
public void setTo(String to) {
this.to = to;
public void setFrom(String from) {
this.from = from;
public void setSubject(String subject) {
this.subject = subject;
public void setMessage(String message) {
this.message = message;
/* Sends Email */
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("Could not send email.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
} catch (MessagingException e) {
throw new Exception("Caught in sendMail" + e.getMessage());
/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
return false;
if((this.to.indexOf("@") == -1) ||
(this.to.indexOf(".") == -1))
return false;
if((this.from.indexOf("@") == -1) ||
(this.from.indexOf(".") == -1))
return false;
return true;
}and the error i get is:
org.apache.jasper.JasperException: Exception in JSP: /processingPages/mailer.jsp:17
14: mailer.setFrom("[email protected]");
15: mailer.setSubject("mailer test");
16: mailer.setMessage("TEst test test");
17: mailer.sendMail();
18:
19: %>
20: </jsp:useBean>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: Unknown SMTP host: mail.yourisp.com
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.processingPages.mailer_jsp._jspService(mailer_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.lang.Exception: Unknown SMTP host: mail.yourisp.com
mailer.MailerBean.sendMail(MailerBean.java:54)
org.apache.jsp.processingPages.mailer_jsp._jspService(mailer_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
Tomcat logs give:
Jul 15, 2009 10:50:35 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.Exception: Unknown SMTP host: mail.yourisp.com
at mailer.MailerBean.sendMail(MailerBean.java:54)
at org.apache.jsp.processingPages.mailer_jsp._jspService(mailer_jsp.java:67)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:773)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:895)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
If anyone needs any other details feel free to ask.
Any help or any pointers to a place to find a solution would be deeply appreciated
ThanksAll I can see is that you are running this in a web application. In most web application containers there's a place where you configure your mail providers and mail sessions. You seem to be ignoring that (you aren't using JNDI to get a session for example) but you are getting the default instance, so perhaps that uses that configuration anyway.
-
Unknown SMTP host exception...
Hi all...
am a newbie in j2ee...i have to send mails from my application...
have written the code...but it gives an error like the smtp host specified, is
unknown...
can anyone pleaz tell me what r the things to be set up or what r the configurations to be done to send a mail using program...am using Transport.send(message) function to do it...plz help me...
thanx and regards,
sand...Hi,
As mentioned in the debugging steps, I turned the debugging session on by "session.setDebug(true);".I got the following printed on my console:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
MessagingException
javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
nested exception is:
java.net.UnknownHostException: smtp.gmail.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1280)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at sendMail.main(sendMail.java:28)
Caused by: java.net.UnknownHostException: smtp.gmail.com
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.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 7 more
I also tried to use telnet to connect as
telnet smtp.gmail.com 25
Here I got an output like
Connecting To smtp.gmsil.com...Could not open connection to the host, on port 25
: Connect failed
so now I donot understand wher the problem lies actually.
Can you please suggest anything?
Thanks -
Javax.mail.MessagingException: Could not connect to SMTP host:
here is a part of my code
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Mail {
/** Creates a new instance of PostMail */
public Mail() {
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp."_____".com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
Here is the exception i rec'vd
javax.mail.MessagingException: Could not connect to SMTP host: smtp.google.com, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at Mail.postMail(Mail.java:45)
at ArchMain.<init>(ArchMain.java:30)
at ArchMain$6.run(ArchMain.java:360)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
... 17 morepackage MailDao;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;
import java.text.*;
import java.text.DateFormat.* ;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.activation.*;
import javax.mail.search.*;
import java.util.Vector.*;
import java.sql.*;
public class SendMail {
String SMTP_HOST_NAME = "smtp.techpepstechnology.com";//smtp.genuinepagesonline.com"; //techpepstechnology.com";
String SMTP_AUTH_USER = "[email protected]"; //[email protected]"; //techpeps";
String SMTP_AUTH_PWD = "demo"; //techpeps2007";
public void postMail( String recipients[ ], String subject,
String message , String from,String msgType) throws MessagingException {
boolean debug = false;
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
// create a message
MimeMessage msg = new MimeMessage(session);
// MimeMessage mimemessage = new MimeMessage(simplemailuser.getSession());
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
if(msgType.equalsIgnoreCase("")) {
//mimemessage.setText(s4);
msg.setContent(message, "text/plain");
else {
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText(message);
MimeBodyPart fileBodyPart = new MimeBodyPart();
FileDataSource fds = new FileDataSource(msgType);
fileBodyPart.setDataHandler(new DataHandler(fds));
fileBodyPart.setFileName(fds.getName());
//step:5 create the multipart/container to hold the part
Multipart container = new MimeMultipart();
container.addBodyPart(textBodyPart);
container.addBodyPart(fileBodyPart);
//step:6 add the multipart to the actual message
msg.setContent(container);
try{
Transport transport=session.getTransport("smtp");
transport.connect();
transport.send(msg);
transport.close();
}catch(Exception e) {
e.printStackTrace();
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
public static void main(String arg[]) {
SendMail sm = new SendMail();
String[] s ={"[email protected]"};
try{
sm.postMail(s,"hello","This is testing of mail","[email protected]","");
catch(Exception e)
e.printStackTrace();
//sm.sendMsg("demo", "demo");
System.out.println("Mail Sent");
i also got the follwing error this code work fine in jcreator but i used this in netbeans it throws a exception
plz.....help
javax.mail.MessagingException: Could not connect to SMTP host: smtp.techpepstechnology.com, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:867)
Mail Sent
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:156)
at javax.mail.Service.connect(Service.java:256)
at javax.mail.Service.connect(Service.java:135)
at javax.mail.Service.connect(Service.java:87)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:93)
at MailDao.SendMail.postMail(SendMail.java:86)
at MailDao.SendMail.main(SendMail.java:110) -
Mail doesn't send - javax.mail.MessagingException: 250
Hello all,
I'm new to JavaMail. I actually started with it last night. I've successfully sent a number of messages, but I randomly get a strange exception for no apparent reason.
If I run the exact same code several times, it will produce this error about every 5 or 6 times:
javax.mail.MessagingException: 250 Requested mail action okay, completed
Does anyone know what might be going on? Thanks in advance for any help you might can give.
Here is the heart of my code:
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host1);
// Get session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(fromAddress));
// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
// Set the subject
message.setSubject(subject);
// Set the content
message.setContent(content, "text/html");
// Send message
Transport.send(message);
Below is the debugger output: (certain values have been removed for anonymity's sake)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG: SMTPTransport trying to connect to host "xx.xx.xx.xx", port 25
DEBUG SMTP RCVD: 220 domain.company.com ESMTP MailEnable Service, Version: 1.704-- ready at 01/14/04 14:07:27
DEBUG: SMTPTransport connected to host "xx.xx.xx.xx", port: 25
DEBUG SMTP SENT: EHLO licensing
DEBUG SMTP RCVD: 502
DEBUG SMTP SENT: HELO licensing
DEBUG SMTP RCVD: 250-AUTH LOGIN
250-SIZE 5120000
250-HELP
250 AUTH=LOGIN
DEBUG SMTP: use8bit false
DEBUG SMTP SENT: MAIL FROM:<[email protected]>
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
DEBUG SMTP SENT: RCPT TO:<[email protected]>
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
Verified Addresses
[email protected]
DEBUG SMTP SENT: DATA
DEBUG SMTP RCVD: 250 Requested mail action okay, completed
DEBUG SMTP SENT: QUITBut I am getting that code thrown as a MessageException; the message never goes through. If you look at the debugging output compared to a message that went through, the DATA transmission commands are screwed up.
Thanks for your input, though. I think I've gotten around this by trying to resend the message. It looks like that when I get this exception the message is never sent. I have a catch that detects this exception and tries to resend up to 3 times.
Thanks,
floosh -
While trying to run a program to sent sms to mobile(with airtel connection)it shows the Error:
"javax.mail.MessagingException: 505 5.7.3 Client was not Authenticated.
If anyone knows how to resolve this problem please reply.
The Code is as follows:
import java.io.*;
import java.net.InetAddress;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class EmailSMS
String TO;
String FROM;
String SUBJECT,TEXT,MAILHOST,LASTERROR;
public static void main(String [] args) throws Exception
EmailSMS SMS=new EmailSMS();
SMS.setMailHost("kcsl.com");
SMS.setTo("[email protected]");
SMS.setFrom("[email protected]");
SMS.setSubject("");
SMS.setText("Hello World");
boolean ret = SMS.send();
if(ret){
System.out.println("SMS was sent");
else
System.out.println("SMS was not sent"+SMS.getLastError());
public EmailSMS()
TO=null;
FROM=null;
SUBJECT=null;
TEXT=null;
LASTERROR="No methods calls";
public void setTo(String to){TO=to;}
public String getTo(){return TO;}
public void setFrom (String from){FROM=from;}
public String getFrom(){ return FROM;}
public void setSubject(String subject){SUBJECT=subject;}
public String getSubject(){return SUBJECT;}
public void setText(String text){TEXT=text;}
public void setMailHost(String host){MAILHOST=host;}
public String getMailHost(){return MAILHOST;}
public String getLastError(){return LASTERROR;}
public boolean send()
int maxLength;
int msgLength;
//Check to make sure that the parameters are correct
if(TO.indexOf("mobile.att.net")>0)
maxLength=140;
else if(TO.indexOf("messaging.nextel.com")>0)
{maxLength=280;}
else if(TO.indexOf("messaging.sprintpcs.com")>0)
{maxLength=100;}
else maxLength=160;
msgLength=FROM.length()+1+SUBJECT.length()+1+TEXT.length();
if(msgLength>maxLength)
LASTERROR="SMS length too long";
return false;
//set email properties
Properties props=System.getProperties();
if(MAILHOST!=null){props.put("mail.smtp.host",MAILHOST);}
Session session=Session.getDefaultInstance(props,null);
try{
Message msg=new MimeMessage(session);
if(FROM!=null){msg.setFrom(new InternetAddress(FROM));}
else{msg.setFrom();}
msg.setSubject(SUBJECT);
msg.setText(TEXT);
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(TO,false));
msg.setSentDate(new Date());
Transport.send(msg);
LASTERROR="Success";
return true;
catch(MessagingException max ){LASTERROR=max.getMessage();
return false;}
thankuHi,
it seems to me that you must authenticate with your smtp host. In order to do so, try following:
While trying to run a program to sent sms to
mobile(with airtel connection)it shows the Error:
"javax.mail.MessagingException: 505 5.7.3 Client was
not Authenticated.
If anyone knows how to resolve this problem please
reply.
The Code is as follows:
import java.io.*;
import java.net.InetAddress;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class EmailSMS
String TO;
String FROM;
String SUBJECT,TEXT,MAILHOST,LASTERROR;
public static void main(String [] args) throws
Exception
EmailSMS SMS=new EmailSMS();
SMS.setMailHost("kcsl.com");
SMS.setTo("[email protected]");
SMS.setFrom("[email protected]");
SMS.setSubject("");
SMS.setText("Hello World");
boolean ret = SMS.send();
if(ret){
System.out.println("SMS was sent");
else
System.out.println("SMS was not
t sent"+SMS.getLastError());
public EmailSMS()
TO=null;
FROM=null;
SUBJECT=null;
TEXT=null;
LASTERROR="No methods calls";
public void setTo(String to){TO=to;}
public String getTo(){return TO;}
public void setFrom (String from){FROM=from;}
public String getFrom(){ return FROM;}
public void setSubject(String
subject){SUBJECT=subject;}
public String getSubject(){return SUBJECT;}
public void setText(String text){TEXT=text;}
public void setMailHost(String host){MAILHOST=host;}
public String getMailHost(){return MAILHOST;}
public String getLastError(){return LASTERROR;}
public boolean send()
int maxLength;
int msgLength;
//Check to make sure that the parameters are correct
if(TO.indexOf("mobile.att.net")>0)
maxLength=140;
else if(TO.indexOf("messaging.nextel.com")>0)
{maxLength=280;}
else if(TO.indexOf("messaging.sprintpcs.com")>0)
{maxLength=100;}
else maxLength=160;
msgLength=FROM.length()+1+SUBJECT.length()+1+TEXT.leng
h();
if(msgLength>maxLength)
LASTERROR="SMS length too long";
return false;
//set email properties
Properties props=System.getProperties();
if(MAILHOST!=null){props.put("mail.smtp.host",MAILHOST
Session
session=Session.getDefaultInstance(props,null);
try{ // Get a Transport object to send e-mail
Transport bus = session.getTransport("smtp");
// Connect only once here
// Transport.send() disconnects after each send
bus.connect(host, username, password);
Message msg=new MimeMessage(session);
if(FROM!=null){msg.setFrom(new
w InternetAddress(FROM));}
else{msg.setFrom();}
msg.setSubject(SUBJECT);
msg.setText(TEXT);
msg.setRecipients(Message.RecipientType.TO,InternetAd
ress.parse(TO,false));
msg.setSentDate(new Date());// Send message
bus.send(msg);
bus.close();
LASTERROR="Success";
return true;
catch(MessagingException max
){LASTERROR=max.getMessage();
return false;}
thankuGood luck -
Exception in thread "main" javax.mail.MessagingException: [EOF]
hi i have a new Application which i need to send Email from it to people
i have tried the code in my university pc's and i works soo fine...but in my home
it gave my error
here is the code
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class TestMail
public static void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "mx2.hotmail.com");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
addressTo[i] = new InternetAddress(recipients);
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
public static void main(String args[])throws MessagingException
String mailers[] = new String[1];
mailers[0] = "[email protected]";
postMail(mailers,"hello","hello my dear ay","[email protected]");
}and here is the output of the programe(the error)Exception in thread "main" javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
512)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at TestMail.postMail(TestMail.java:39)
at TestMail.main(TestMail.java:45)
Press any key to continue . . .plz help meee
Edited by: mld on Dec 30, 2007 9:37 AM
Edited by: mld on Dec 31, 2007 2:32 AMi have tried every thing
i put stmp.bebug in my code and it gave me the following (tis is a part of the output...the other is not important)
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: not loading file: C:\Program Files\Java\jdk1.5.0_06\jre\lib\javamail.addr
ess.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_06\jre\lib\
javamail.address.map (The system cannot find the file specified)
Exception in thread "main" javax.mail.MessagingException: [EOF]
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
512)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at TestMail.postMail(TestMail.java:43)
at TestMail.main(TestMail.java:49)
Press any key to continue . . . -
Javax.mail.MessagingException: 505 Client was not authenticated
Hi!,
I got the following error:
Exception in thread "main" javax.mail.MessagingException: 505 Client was not authenticated
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:507)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:312)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:168)
at HelloMail.main(HelloMail.java:35)
This is the code:
To send an email I need authentification, and I include the mail.smtp.auth propertie and
"message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect("mail.xxx.com.mx","harriaga",passw);
transport.sendMessage(message,message.getAllRecipients());
transport.close();"
Do you know if I am skip something.
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class HelloMail {
public static void main(String args[]) throws Exception {
String host="mail.xxx.com.mx"; //obviously doesn't work
String from="[email protected]"; //sender's email
String to ="[email protected]" ; //receiver's email
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session=Session.getInstance(props,null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to));
message.setSubject(" My Test HTML email ");
message.setText(" Here is the content ");
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect("mail.xxx.com.mx","harriaga",passw);
transport.sendMessage(message,message.getAllRecipients());
transport.close();
Thanks for all,
HAG.HAG,
you need to create a session object passing a valid authenticator. In other words,
MyAuthenticator auth = new MyAuthenticator ();
Session session = Session.getInstance(props, auth);where MyAuthenticator is something like
public class MyAuthenticator extends Authenticator{
public PasswordAuthentication getPasswordAutentication(){
return new PasswordAuthentication( "user", "password");
}You obviously need to replace username and password with data valid for your e-mail account.
Hope this helps,
gulfi -
I am getting this exception , while my application is trying to send mails. The complete stack trace is below
com.bp.ebus.downstream.util.ErrorLevelException: javax.mail.MessagingException: 452 4.4.5 Insufficient disk space; try again
later
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:879)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:599)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:319)
at com.bp.ebus.interfaces.SmtpClient.sendMessage(SmtpClient.java:252)
at com.bp.ebus.interfaces.SmtpClient.send(SmtpClient.java:191)
at com.bp.ebus.downstream.ejb.ServicesSessionBean.sendNewEmails(ServicesSessionBean.java:105)
at com.bp.ebus.downstream.ejb.ServicesSessionBean_f7hinc_EOImpl.sendNewEmails(ServicesSessionBean_f7hinc_EOImpl.java:
166)
at com.bp.ebus.downstream.ejb.ServicesSessionBean_f7hinc_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:85)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:262)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:229)
at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
at $Proxy4.sendNewEmails(Unknown Source)
at com.bp.ebus.lighthouse.jobs.SendEmail.run(SendEmail.java:70)
at java.util.TimerThread.mainLoop(Timer.java:435)
at java.util.TimerThread.run(Timer.java:385)
My OS is solaris and Application server is weblogic.The message is coming from your mail server.
Looks like your server is out of disk space. -
All, while sending email via web production application getting the following exception and it is intermittent as well, any quick pointers in cause/fix, please..
ERROR [nucleusNamespace.atg.dynamo.service.EmailFormHandler] Failed to send meail message:Remember to set /atg/dynamo/service/SMTPEmail.emailHandlerHostName and /atg/dynamo/service/SMTPEmail.emailHandlerPort
atg.service.email.EmailException: javax.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketTimeoutException: Read timed out
at atg.service.email.SMTPEmailSender.sendEmailMessage(SMTPEmailSender.java:907)
at atg.service.email.SMTPEmailSender.sendEmailMessage(SMTPEmailSender.java:930)
at atg.service.email.SMTPEmailSender.sendEmail(SMTPEmailSender.java:1009)
at atg.service.email.SMTPEmailSender.sendEmailEvent(SMTPEmailSender.java:985)
at atg.service.email.SMTPEmailSender.sendEmailMessage(SMTPEmailSender.java:522)
at atg.service.email.EmailFormHandler.sendMail(EmailFormHandler.java:316)
at atg.service.email.EmailFormHandler.handleSendEmail(EmailFormHandler.java:436)
at sun.reflect.GeneratedMethodAccessor843.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at atg.droplet.EventSender.sendEvent(EventSender.java:582)
at atg.droplet.FormTag.doSendEvents(FormTag.java:791)
at atg.droplet.FormTag.sendEvents(FormTag.java:640)
at atg.droplet.DropletEventServlet.sendEvents(DropletEventServlet.java:523)
at atg.droplet.DropletEventServlet.service(DropletEventServlet.java:550)
at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:116)
at atg.servlet.sessionsaver.SessionSaverServlet.service(SessionSaverServlet.java:2442)
at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:116)
at atg.commerce.order.CommerceCommandServlet.service(CommerceCommandServlet.java:128)
at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:116)
at atg.commerce.promotion.PromotionServlet.service(PromotionServlet.java:191)
at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:116)
at atg.userprofiling.AccessControlServlet.service(AccessControlServlet.java:602)Check the configuration of /atg/dynamo/service/SMTPEmail component and specify proper values for emailHandlerHostName, emailHandlerPort, username, password. By default emailHandlerHostName is configured to localhost and port is set to 25 which is default for SMTP. If you do not know these you can get these details from your mail administrator who has setup your mail-id. You would also need to specify the username and password if your administrator has not allowed for making anonymous connection to the mail server.
-
Javax.mail.MessagingException: A5 BAD Command Argument Error. 12;
This error appeared on mailboxes hosted on Exchange 2007. It happens when a folder is searched with 11+ OR terms. It works fine with <= 10 subjectTerm items OR'ed together. The search term does not matter. The mailboxes are migrating from Exchange 2003 where the problem does not occur. I tested 51 OR'ed subject terms against the 2003 mailbox and it works fine. I didn't test beyond 51 terms.
I upgraded to JavaMail 1.4.2 and the problem still exists.
I'm not sure if this is a JavaMail bug or an error with Exchange 2007.
Here is the output generated with session debugging enabled against Exchange 2007:
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "qtdenexcam20.ad.domain.com", port 143, isSSL false
* OK Microsoft Exchange Server 2007 IMAP4 service ready
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
DEBUG: protocolConnect login, host=qtdenexcam20.ad.domain.com, user=userid, password=<non-null>
A1 AUTHENTICATE PLAIN
+
d21kZXYAd21kZXYAUXczc3QyMDA4
A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
Opening email folders.
DEBUG: connection available -- size: 1
A3 SELECT INBOX
* 23 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UNSEEN 6] Is the first unseen message
* OK [UIDVALIDITY 765] UIDVALIDITY value
* OK [UIDNEXT 15790] The next unique identifier value
A3 OK [READ-WRITE] SELECT completed.
A4 LIST INBOX ""
* LIST (\Noselect \HasChildren) "/" ""
A4 OK LIST completed.
* OK Microsoft Exchange Server 2007 IMAP4 service ready
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
A1 AUTHENTICATE PLAIN
+
d21kZXYAd21kZXYAUXczc3QyMDA4
A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
IMAP DEBUG: AUTH: GSSAPI
IMAP DEBUG: AUTH: PLAIN
A3 LIST "" Folders/processed_items_LARG
* LIST (\HasChildren) "/" Folders/processed_items_LARG
A3 OK LIST completed.
A4 LIST "" Folders/junk_LARG
* LIST (\HasNoChildren) "/" Folders/junk_LARG
A4 OK LIST completed.
Retrieving all messages from: INBOX
23 messages retrieved.
Processing junk email.
*** Searching for junk mail ***
A5 SEARCH OR OR OR OR OR OR OR OR OR OR SUBJECT test1 SUBJECT test2 SUBJECT test3 SUBJECT test4 SUBJECT test5 SUBJECT test6 SUBJECT test7 SUBJECT test8 SUBJE
CT test9 SUBJECT test10 SUBJECT test11 1:23
A5 BAD Command Argument Error. 12
Exception caught in main while processing config/email.larg.properties.
javax.mail.MessagingException: A5 BAD Command Argument Error. 12;
nested exception is:
com.sun.mail.iap.BadCommandException: A5 BAD Command Argument Error. 12
javax.mail.MessagingException: A5 BAD Command Argument Error. 12;
nested exception is:
com.sun.mail.iap.BadCommandException: A5 BAD Command Argument Error. 12
at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1706)
at com.domain.nroc.email.WMSEmailAgent.processJunkEmail(Unknown Source)
at com.domain.nroc.email.WMSEmailAgent.main(Unknown Source)
Caused by: com.sun.mail.iap.BadCommandException: A5 BAD Command Argument Error. 12
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:338)
at com.sun.mail.imap.protocol.IMAPProtocol.issueSearch(IMAPProtocol.java:1550)
at com.sun.mail.imap.protocol.IMAPProtocol.search(IMAPProtocol.java:1458)
at com.sun.mail.imap.protocol.IMAPProtocol.search(IMAPProtocol.java:1433)
at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1687)
... 2 more
I'll post the Exchange 2003 debug output in a follow-up message because this message is exceeding the length limit.Here is the output generated with session debugging enabled against Exchange 2003 (and 51 subject terms):
DEBUG: setDebug: JavaMail version 1.4.2
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "itdene2km05.ad.domain.com", port 143, isSSL false
* OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1 (ITDENE2KM05.AD.DOMAIN.COM) ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
DEBUG: protocolConnect login, host=itdene2km05.ad.domain.com, user=ad\userid, password=<non-null>
A1 LOGIN "ad\\userid" pass
A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A2 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
Opening email folders.
DEBUG: connection available -- size: 1
A3 SELECT INBOX
* 1 EXISTS
* 0 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UIDVALIDITY 597925] UIDVALIDITY value
A3 OK [READ-WRITE] SELECT completed.
A4 LIST INBOX ""
* LIST (\Noselect) "/" ""
A4 OK LIST completed.
* OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1 (ITDENE2KM05.AD.DOMAIN.COM) ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A0 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
A1 LOGIN "ad\\userid" pass
A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 IDLE LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE LITERAL+ UIDPLUS CHILDREN AUTH=NTLM
A2 OK CAPABILITY completed.
IMAP DEBUG: AUTH: NTLM
A3 LIST "" Folders/processed_items_LARG
* LIST (\HasChildren) "/" Folders/processed_items_LARG
A3 OK LIST completed.
A4 LIST "" Folders/junk_LARG
* LIST (\HasNoChildren) "/" Folders/junk_LARG
A4 OK LIST completed.
Retrieving all messages from: INBOX
1 messages retrieved.
Processing junk email.
*** Searching for junk mail ***
A5 SEARCH OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR OR
OR SUBJECT test1 SUBJECT test2 SUBJECT test3 SUBJECT test4 SUBJECT test5 SUBJECT test6 SUBJECT test7 SUBJECT test8 SUBJECT test9 SUBJECT test10 SUBJECT test1
1 SUBJECT test12 SUBJECT test13 SUBJECT test14 SUBJECT test15 SUBJECT test16 SUBJECT test17 SUBJECT test18 SUBJECT test19 SUBJECT test20 SUBJECT test21 SUBJE
CT test22 SUBJECT test23 SUBJECT test24 SUBJECT test25 SUBJECT test26 SUBJECT test27 SUBJECT test28 SUBJECT test29 SUBJECT test30 SUBJECT test31 SUBJECT test
32 SUBJECT test33 SUBJECT test34 SUBJECT test35 SUBJECT test36 SUBJECT test37 SUBJECT test38 SUBJECT test39 SUBJECT test40 SUBJECT test41 SUBJECT test42 SUBJ
ECT test43 SUBJECT test44 SUBJECT test45 SUBJECT test46 SUBJECT test47 SUBJECT test48 SUBJECT test49 SUBJECT test50 SUBJECT "Exchange Maintenance" 1
* SEARCH 1
A5 OK SEARCH completed.
1 junk email items identified.
A5 LIST "" Folders/junk_LARG -
Getting nested exception(Unknown SMTP host)
hello
i have written a simple mailclient.i am running the following programme from my local machine which is under proxy server.
public class MailExample {
public static void main (String args[]) throws Exception {
String host = "mail.ab";
String from = "[email protected]";
String to = "[email protected]";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome");
Transport.send(message);
This host is some other machine.
i am getting nested exception as unknown SMTP host.
please help.
thanks in advanceUnknown host: it is telling you that it can't find the host you told it to look for. Either you gave it the name of a system that does not exist, or that system does not have an SMTP host running on it. I would guess the first reason, as "mail.ab" does not look right to me. (What country is "ab" and why is there only one mail server in the entire country?)
-
Hi,
i've a java Mail program which will send the mail thro smtp server.
when i try to execute this program im getting the error javax.mail.MessagingException: [EOF]
i've attached both code & error.
while running the program need to give the arguments
ex : java SendMail smtpserver frommailid tomailid subject body
please provide me the solution.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class SendMail {
public static void main(String[] args) {
try
String smtpServer=args[0];
String to=args[1];
String from=args[2];
String subject=args[3];
String body=args[4];
send(smtpServer, to, from, subject, body);
catch (Exception ex)
System.out.println("Usage: java SendMail"
+" smtpServer toAddress fromAddress subjectText bodyText");
System.exit(0);
public static void send(String smtpServer, String to, String from
, String subject, String body)
try
Properties props = System.getProperties();
props.put("mail.smtp.host", smtpServer);
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate(new Date());
System.out.println("test 1--");
Transport.send(msg);
System.out.println("test 2--");
System.out.println("Message sent OK.");
catch (Exception ex)
ex.printStackTrace();
thanks for the help in advance.
regs
lal.I ran into a similar error today. I fixed it by setting up SMTP authentication because my ISP's help pages said that they would allow only SMTP authentication.
Here is what I did:
Transport transport =
mailConnection.getTransport("smtp");
transport.connect(
"hostname", "email", "password");
Transport.send(msg);
I also passed the following property while creating the session:
props.put("mail.smtp.auth", "true");
finally turning on debug helped:
session.setDebug(true);
session.setDebugOut(null);
Hope this helps -
Javax.mail.MessagingException: Missing start boundary
I use the following code creates a Mime file
MimeMultipart mmp = new MimeMultipart();
MimeBodyPart mbp = null;
// add rootpart
mbp = new MimeBodyPart();
mbp.setContentID("[email protected]");
mbp.setDataHandler(new DataHandler(new FileDataSource(args[0])));
mmp.addBodyPart(mbp);
// add attachment info
for(int i = 1; i < args.length; i = i+2){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(baos);
FileInputStream fis = new FileInputStream(args[i+1]);
byte[] bytes = new byte[1024];
int len;
while((len = fis.read(bytes, 0, 1024)) > 0){
gos.write(bytes, 0, len);
fis.close();
gos.close();
baos.close();
InternetHeaders ih = new InternetHeaders();
ih.addHeader("Content-ID", args);
mbp = new MimeBodyPart(ih, baos.toByteArray());
mmp.addBodyPart(mbp);
String CarriageReturn = String.valueOf(CARRIAGE_RETURN);
String lineFeed = String.valueOf(LINE_FEED);
String horizontaltab = String.valueOf(HORIZONTAL_TAB);
FileOutputStream fos = new FileOutputStream(args[0] + ".mime");
StringBuffer msgParam = new StringBuffer();
msgParam.append("MIME-Version: 1.0");
msgParam.append(CarriageReturn);
msgParam.append(lineFeed);
msgParam.append("Content-Type: ");
msgParam.append(mmp.getContentType().replaceAll(CarriageReturn,"").replaceAll(lineFeed,"").replaceAll(horizontaltab,""));
msgParam.append("; start=\"<[email protected]>\"");
msgParam.append(CarriageReturn);
msgParam.append(lineFeed);
msgParam.append(CarriageReturn);
msgParam.append(lineFeed);
msgParam.append(CarriageReturn);
msgParam.append(lineFeed);
fos.write(msgParam.toString().getBytes());
mmp.writeTo(fos);
fos.close();
I can correctly read the mime file at windows OS,but in linux OS i got the following error Message:
2010/11/19 11:53:40 K101J2EED1 fatal 0041EBFC124735B5B67FFA9F4B3B09961KD1 例外=[javax.mail.MessagingException: Missing start boundary]
sun.reflect.GeneratedMethodAccessor303.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy28.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
jp.terasoluna.fw.web.struts.action.RequestProcessorEx.process(RequestProcessorEx.java:149)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:675)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:324)
jp.co.nttdata.erc.sys.app.extended.ExtendedFilter.doFilter(ExtendedFilter.java:163)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:424)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:324)
jp.co.nttdata.erc.sys.app.extended.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:174)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:424)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:324)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:379)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.catalina.core.LinkedPipeline.invoke(LinkedPipeline.java:475)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:983)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:349)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.tcg.ThreadControlGroupValve.invoke(ThreadControlGroupValve.java:82)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.ejb.management.mbean.web.RequestStatisticsValve.invoke(RequestStatisticsValve.java:72)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:188)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.catalina.core.StandardSessionValve.invoke(StandardSessionValve.java:96)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.catalina.core.LinkedPipeline.invoke(LinkedPipeline.java:475)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:983)
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:3928)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:261)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:197)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.catalina.core.LinkedPipeline.invoke(LinkedPipeline.java:475)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:983)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
com.hitachi.software.web.catalina.core.ValveWrapper.invokeNext(LinkedPipeline.java:672)
com.hitachi.software.web.catalina.core.LinkedPipeline.invoke(LinkedPipeline.java:475)
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:983)
org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:700)
org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:959)
java.lang.Thread.run(Thread.java:620)
Edited by: chengen on Nov 24, 2010 8:26 PM
Edited by: chengen on Nov 24, 2010 9:25 PMI can correctly read the mime file at windows OS,but in linux OS i got the following error Message:That would suggest one or more of the following.
1. An end of line problem. Something is wrong with your use of CR/LF.
2. A line length problem (brief look suggests a 998 limit.)
3. One reader is more lenient than the other. This goes back to 1 and 2.
Maybe you are looking for
-
Universal Dock Adapter 3-Pack for iPod nano 3rd gen.
If i purchase this, will the insert let me charge and play my ipod nano 3rd generation on my IH5 Ihome? Because at the moment i do not have an insert that will let me charge/play it.
-
Using oracle.sql.BLOB data type in Java Class to pass in a Blob
All, I'm trying to pass in a BLOB from PL/SQL to a Java Class, but the BLOB isn't passed correctly. When I check the length of the BLOB in PL/SQL its different from the length of the BLOB in java. I'm using DB 11g and the ojdbc5.jar file in my java c
-
Hey, I'm hoping someone can help. I'm new to asp development and azure. I have made a website and downloaded all the sdks needed to publish from MS Visual Studio 2013. I can create and publish to a domain yet when I click on my domain it gives me a p
-
Enable Database Logon Prompt problem
Post Author: saied CA Forum: .NET I have a report in which I pass the connection information to a connectionInfo object like ConnectionInfo connectionInfo = new ConnectionInfo();connectionInfo.UserID = "user";connectionInfo.Password = "password";conn
-
Can you import fonts into Adobe Ideas and Photoshop Touch?
Thinking about getting these apps and wanted to know if I could download fonts and use them in the apps like you would on a computer. Never had a tablet before either so just wondering if you could and how