How to send e-mail using java mail api
Hi can anyone tell me how to send mail using the javamail api, in short if possible an example code.
Theres already lots of this code in the forums, use the search bar to the left.
Also, there is a dedicated javaMail forum which you will find useful (you are currently in a JSP forum)
http://forum.java.sun.com/forum.jspa?forumID=43
Similar Messages
-
How to send HTML Format Mail using Java Mail in oracle 9i Forms
Dear All
could you please tell me how to send HTML Format Mail using Java Mail in oracle 9i Forms and how to implement the java mail ?
if it is possible, could you please send me the sample code? please very urgent
Thanks
P.SivaramanHello,
<p>Here is a Form sample.</p>
Francois -
How to send Secured Mail using Java Mail?
I want to send mails with "Send Secure" option using Java Mail. Now mails are being sent using Java Mail connecting to smtp host.
Appreciating your help.
Thanks.There are third party libraries to help with this. Bouncy Castle is very popular.
See the [JavaMail Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] page. -
How to Read An Attachment Using Java Mail
Hi
I Am Able To Read The Mail Using Java Mail ,but Unable To Read The Attachment Which Comes Along With The Mail.
Please Help Me , In Reading The Attachment.Hi
I Am Able To Read The Mail Using Java Mail ,but
t Unable To Read The Attachment Which Comes Along
With The Mail.
Please Help Me , In Reading The Attachment.Do you mean:
- I only recieve .txt or .doc attachments and I want to see the contents? Or could you get a .jpg as well?
or
- Do you need to seperate the attachment from the e-mail and then view it? -
Sending HTML E Mail using Java Mail
Can anybody please tell me how to send HTML email using JavaMail. I know I need the DataContentHandler for text/html mime type but where can I find one? If anybody has better suggestions you are welcome.
Folks,
I've used what you have suggested. Though it compiled, I kept getting this java error
--Exception in MailServer.java
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: IOException while sending message;nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type text/html
at javax.mail.Transport.send0(Transport.java:204)
at javax.mail.Transport.send(Transport.java:73)
at MailTest.send(MailTest.java:419)
at MailTest.sendThruDefaultServer(MailTest.java:319)
at MailTest.main(MailTest.java:476)
[sendEmail() - Exception :javax.activation.UnsupportedDataTypeException
HELP! -
How to send html messages using unix mail ?
Hi,
I'm wondering if it's possible to send html formated mail using Unix mail command ?
Regards,
Didier.It works fine for me right out of the box; I've done zero to configure anything. In my case, I presume the HTML is encoded in a file. Then I invoke a script which adds the following mail headers before the HTML, then calls sendmail:
<pre class=command>MIME-Version: 1.0
Content-type: text/html; charset=ISO-8859-1
To: $address
From: $MY_EMAIL
Subject: File: $subject
</pre>
In the header, variables $address, $MY_EMAIL, and $subject are filled in by the shell script.
HTH -
How to send sms,Email using java
how to send sms,Email using java
Hi,
There are many sms gateways that have their own api to send sms. You can use them for sms. (They will charge you for the sms!!!)
Moderator edit: Link removed
Thanks
Edited by: PhHein on 20.10.2010 16:11 -
How to print PDF files using java print API
Hi,
I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
Thanks in advanceMike,
Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
boolean showPrintDialog=true;
PrinterJob printJob = PrinterJob.getPrinterJob ();
printJob.setJobName ("Contract.pdf");
try {
if (showPrintDialog) {
if (printJob.printDialog()) {
printJob.print();
else
printJob.print ();
} catch (Exception PrintException) {
PrintException.printStackTrace();
Thank you and a happy new year.
Cheers,
Chris -
How to send picture message using J2ME sms APIs?
Hi,
I experiment with SMS APIs, i successfully send simple text message. now i want to send picture message, how to send picture message using J2ME APIs.
please guide me.
guna.I experienced in coding sending and receiving sms in J2ME. Besides, I also esperienced in coding reading a binary file in a applicaition jar. But I never done these both together. Hence Im not sure it works or not. Below is the example to open and read a binary file:
InputStream oInputStream = getClass().getResourceAsStream( "/picture.png" );
if(oInputStream == null) {
//File does not exist;
throw new Exception("File not found");
//Read the binary file and copy it to a byte array
byte[] abyPicture = new byte[oInputStream.available()];
oInputStream.read(abyPicture ); -
How to calculate call duration using java card API
Hi,
I am developing an application using Java card API. I want to calculate duration of otgoing calls in it. I am trying to start timer at the beginning of call in Call Control event. Can someone kindly check following code of Call control event? Here timerManagement function is sending proactive command for starting timer for 3 hours. Here I am asuming that maximum call will be of 3 hours. In callDisconnect event i can get current value of timer and use it to calculate duration of call. But this scenario is also not working.
Problem is that during code execution program stuck at send command (proHdlr.send();) of timmerManagement function. I am sending postAsBERTLV command before starting timer so may be reason is that it is not possible to send proactive command while phone is busy.
But I also cannot send postAsBERTLV after timerManagement function. Because it is mention in specification that "The EnvelopeResponseHandler content must be posted before the first invocation of a ProactiveHandler.send method or before the termination of the processToolkit, so that the GSM applet can offer these data to the ME (eg 9Fxx/9Exx/91xx). After the first invocation of the ProactiveHandler.send method the EnvelopeResponseHandler is no more available"
Take a look at following code
* Method illustrating the use of the Call Control event.
private void callControlService() {
/** @todo: Replace following sample code with your implementation */
ProactiveHandler proHdlr = ProactiveHandler.getTheHandler();
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
ProactiveResponseHandler rspHdlr = ProactiveResponseHandler
.getTheHandler();
EnvelopeResponseHandler envRspHdlr = EnvelopeResponseHandler
.getTheHandler();
durationCount = 0;
// allow call with no modifications
envRspHdlr.postAsBERTLV((byte)0x9F, (byte)0x00);
// start clock using timer
timerManagement(proHdlr, rspHdlr, (byte) 0x0, timer_id, tempBuffer);
return;
}Please help me in this regard
Thanks
YasirI am also unable to start timer in call connected event. I cannot send any proactive command while phone is busy. I am using Gemalto development Suite and there simulators (Simulation 2G chain).
Is it limitation of simulator that you cannot send any proactive command while phone is busy?
Is there any other work around for getting call duration? -
How to send multiple Recipients using the mail.jar and activation.jar
hi!
could somebody help me. how do i send multiple Recipient using mail.jar. when i would input 2email address in to Recipient
(example: [email protected], [email protected])
i get a DEBUG: setDebug: JavaMail version 1.3.2
but if i send a single email it just works properly.
heres my code
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public class SendMail
public SendMail(String to, String from, String subject, String body)
//public SendMail(String to)
String message_recip = to;
String message_subject = subject;
String message_cc = "";
String message_body = body;
//The JavaMail session object
Session session;
//The JavaMail message object
Message mesg;
// Pass info to the mail server as a Properties, since JavaMail (wisely) allows room for LOTS of properties...
Properties props = new Properties( );
// LAN must define the local SMTP server as "mailhost" to be able to send mail...
//props.put("mail.smtp.host","true");
props.put("mail.smtp.host", "mailhost");
// Create the Session object
session = Session.getDefaultInstance(props, null);
session.setDebug(true);
try
// create a message
mesg = new MimeMessage(session);
// From Address - this should come from a Properties...
mesg.setFrom(new InternetAddress(from));
// TO Address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
// CC Address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
// The Subject
mesg.setSubject(message_subject);
// Now the message body.
mesg.setText(message_body);
// XXX I18N: use setText(msgText.getText( ), charset)
// Finally, send the message!
Transport.send(mesg);
}//end of try
catch (MessagingException ex)
while ((ex = (MessagingException)ex.getNextException( )) != null)
ex.printStackTrace( );
}//end of while
}//end of catch
}//end of SendMail
public static void main(String[] args)
//String t = "[email protected], [email protected]"; - this I think causes error
String t = "[email protected]";
String f = "[email protected]";
String s = "Hello World";
String b = "the quick brown fox jumps over the lazy dog";
SendMail sm = new SendMail(t,f,s,b);
}//end of main
}//end of class
could someone please help me im stuck-up with this. thanx!i need it ASAP
i am a beginner in java and jsp
Need to knw how can I parse the addresss field
Below
is the code
<code>
package
public class EMailBean {
private String smtp,username,password,from,bcc,subject,body,attachments,cc;
/*setter*/
public void setSmtp(String str){this.smtp=str;}
public void setUsername(String str){this.username=str;}
public void setPassword(String str){this.password=str;}
public void setFrom(String str){this.from=str;}
public void setTo(String str){this.to=str;}
public void setCc(String str){this.cc=str;}
public void setBcc(String str){this.bcc=str;}
public void setSubject(String str){this.subject=str;}
public void setBody(String str){this.body=str;}
public void setAttachments(String str){this.attachments=str;}
/*getter*/
public String getSmtp( ){return this.smtp;}
public String getUsername( ){return this.username;}
public String getPassword( ){return this.password;}
public String getFrom( ){return this.from;}
public String getTo( ){return this.to;}
public String getCc( ){return this.cc;}
public String getBcc( ){return this.bcc;}
public String getSubject( ){return this.subject;}
public String getBody( ){return this.body;}
public String getAttachments( ){return this.attachments;}
</code>
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(mail.getFrom()));
msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(mail.getTo()));
msg.addRecipient(Message.RecipientType.CC, new InternetAddress(mail.getCc()));
msg.addRecipient(Message.RecipientType.CC, new InternetAddress("[email protected]"));
msg.setSubject(mail.getSubject());
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText(mail.getBody());
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(mail.getAttachments());
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(source.getName());
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
msg.setSentDate(new Date());
Transport t = session.getTransport("smtp");
try {
t.connect(mail.getUsername(), mail.getPassword());
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
result = result + "<FONT SIZE='4' COLOR='blue'><B>Success!</B>"+"<FONT SIZE='4' COLOR='black'> "+"<HR><FONT color='green'><B>Mail was successfully sent to </B></FONT>: "+mail.getTo()+"<BR>";
if (!("".equals(mail.getCc())))
result = result +"<FONT color='green'><B>CCed To </B></FONT>: "+mail.getCc()+"<BR>";
if (!("".equals(mail.getBcc())))
result = result +"<FONT color='green'><B>BCCed To </B></FONT>: "+mail.getBcc() ;
result = result+"<BR><HR>";
} catch (MessagingException mex) {
result = result + "<FONT SIZE='4' COLOR='blue'> <B>Error : </B><BR><HR> "+"<FONT SIZE='3' COLOR='black'>"+mex.toString()+"<BR><HR>";
} catch (Exception e) {
result = result + "<FONT SIZE='4' COLOR='blue'> <B>Error : </B><BR><HR> "+"<FONT SIZE='3' COLOR='black'>"+e.toString()+"<BR><HR>";
e.printStackTrace();
finally {
return result;
} -
Problem in sending mail using java mail api
This is the pogram I am using as of now to send a mail to yahoo id.
import javax.mail.*;
import javax.mail.internet.*;
public class SendingMail2
public SendingMail2()
try
String from = "ravikiran_sunrays";
String to = "[email protected]";
String subject = "the subject u wanna send ";
String cc="[email protected]";
String bcc="[email protected]";
String text="the matter that u wanna send ";
java.util.Properties prop = System.getProperties();
prop.put("mail.smtp.host","mail.yahoo.com");
//prop.put("http.proxyHost",System.getProperty("http.proxyHost"));
//prop.put("http.proxyPort","8080");
//prop.put("http.proxyPort",System.getProperty("http.proxyPort"));
//prop.put("http.proxyHost","172.19.48.201");
//System.getProperties().setProperty("http.proxyPort","8080");
//System.getProperties().setProperty("http.proxyHost","172.19.48.201");
Session ses = Session.getInstance(prop,null);
MimeMessage message = new MimeMessage(ses);
try
Address fromAddress = new InternetAddress(from);
message.setFrom(fromAddress);
message.setSubject(subject);
Address[] toAddress = InternetAddress.parse(to);
Address[] cc_address=InternetAddress.parse(cc);
Address[] bcc_address=InternetAddress.parse(bcc);
message.setRecipients(Message.RecipientType.TO,toAddress);
message.setRecipients(Message.RecipientType.CC,cc_address);
message.setRecipients(Message.RecipientType.BCC,bcc_address);
message.setSentDate(new java.util.Date());
message.setText(text);
Transport.send(message);
System.out.println("Mail Successfully Sent");
catch(Exception e)
System.out.println("Problem " + e);
catch(Exception e)
System.out.println("Problem " + e);
public static void main(String[] args)
SendingMail2 sendingMail2 = new SendingMail2();
This is the exception I am getting when I try 2 execute that program.
avax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Unknown SMTP host: mail.yahoo.com;
nested exception is:
java.net.UnknownHostException: mail.yahoo.comlisten buddy
this is a class i made it is easy to understand it sends mails and check inbox just adduser from telnet with remote manager in james create the three accounts i am using and then use this class and its methods
also the next class that contains the mails test my class and what i am saying
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class MailClient
extends Authenticator
public static final int SHOW_MESSAGES = 1;
public static final int CLEAR_MESSAGES = 2;
public static final int SHOW_AND_CLEAR =
SHOW_MESSAGES + CLEAR_MESSAGES;
protected String from;
protected Session session;
protected PasswordAuthentication authentication;
public MailClient(String user, String host)
this(user, host, false);
public MailClient(String user, String host, boolean debug)
from = user + '@' + host;
authentication = new PasswordAuthentication(user, user);
Properties props = new Properties();
props.put("mail.user", user);
props.put("mail.host", host);
props.put("mail.debug", debug ? "true" : "false");
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");
session = Session.getInstance(props, this);
public PasswordAuthentication getPasswordAuthentication()
return authentication;
public void sendMessage(
String to, String subject, String content)
throws MessagingException
System.out.println("SENDING message from " + from + " to " + to);
System.out.println();
MimeMessage msg = new MimeMessage(session);
msg.addRecipients(Message.RecipientType.TO, to);
msg.setSubject(subject);
msg.setText(content);
Transport.send(msg);
public void checkInbox(int mode)
throws MessagingException, IOException
if (mode == 0) return;
boolean show = (mode & SHOW_MESSAGES) > 0;
boolean clear = (mode & CLEAR_MESSAGES) > 0;
String action =
(show ? "Show" : "") +
(show && clear ? " and " : "") +
(clear ? "Clear" : "");
System.out.println(action + " INBOX for " + from);
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs = inbox.getMessages();
if (msgs.length == 0 && show)
System.out.println("No messages in inbox");
for (int i = 0; i < msgs.length; i++)
MimeMessage msg = (MimeMessage)msgs;
if (show)
System.out.println(" From: " + msg.getFrom()[0]);
System.out.println(" Subject: " + msg.getSubject());
System.out.println(" Content: " + msg.getContent());
if (clear)
msg.setFlag(Flags.Flag.DELETED, true);
inbox.close(true);
store.close();
System.out.println();
====================================
testing this class
=======================================
public class JamesConfigTest
public static void main(String[] args)
throws Exception
// CREATE CLIENT INSTANCES
MailClient redClient = new MailClient("red", "localhost");
MailClient greenClient = new MailClient("green", "localhost");
MailClient blueClient = new MailClient("blue", "localhost");
// CLEAR EVERYBODY'S INBOX
redClient.checkInbox(MailClient.CLEAR_MESSAGES);
greenClient.checkInbox(MailClient.CLEAR_MESSAGES);
blueClient.checkInbox(MailClient.CLEAR_MESSAGES);
Thread.sleep(500); // Let the server catch up
// SEND A COUPLE OF MESSAGES TO BLUE (FROM RED AND GREEN)
redClient.sendMessage(
"blue@localhost",
"Testing blue from red",
"This is a test message");
greenClient.sendMessage(
"blue@localhost",
"Testing blue from green",
"This is a test message");
Thread.sleep(500); // Let the server catch up
// LIST MESSAGES FOR BLUE (EXPECT MESSAGES FROM RED AND GREEN)
blueClient.checkInbox(MailClient.SHOW_AND_CLEAR);
=======================================================
it suppose to print this
Clear INBOX for red@localhost
Clear INBOX for green@localhost
Clear INBOX for blue@localhost
SENDING message from red@localhost to blue@localhost
SENDING message from green@localhost to blue@localhost
Show and Clear INBOX for blue@localhost
From: green@localhost
Subject: Testing blue from green
Content: This is a test message
From: red@localhost
Subject: Testing blue from red
Content: This is a test message
thanks a lot
but i need ur help plzzzzzzzzzzzz
i can create account from telnet
but how i can create a new account from java .. a jsp page that i made to create a new account on the server
plzzzzzzzz help me
bye -
Not able to sending the Mail using java mail utility
Hi, I am new to java mail utility and written first time for sending mail. If any body an help me out in resolving the problem I would be thankful to him/her........below is the code which I m trying......
package test;
import javax.servlet.http.HttpServlet;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/*import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;*/
* @author chauhasd
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public class SendMailServlet extends HttpServlet{
public SendMailServlet(){
public void sendMail(){
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props=new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host","pcsttc.patni.com");
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable","true");
Session session=Session.getDefaultInstance(props,new MyAuthenticator());
session.setDebug(true);
MimeMessage message=new MimeMessage(session);
try{
message.setContent("Hello....","text/plain");
message.setSubject("Testing Mail");
Address strTo = new InternetAddress("[email protected]");
Address strFrom = new InternetAddress("[email protected]");
Address strReplyTO = new InternetAddress("[email protected]");
message.setFrom(strFrom);
message.setReplyTo(new Address[]{strReplyTO});
message.setRecipient(Message.RecipientType.TO,strTo);
Transport.send(message);
}catch (AddressException e)
// TODO Auto-generated catch block
e.printStackTrace();
}catch (NoSuchProviderException e){
// TODO Auto-generated catch block
e.printStackTrace();
}catch (MessagingException e){
// TODO Auto-generated catch block
e.printStackTrace();
protected PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication("[email protected]", "sid35789");
public static void main(String [] args){
new SendMailServlet().sendMail();
ERROR :
DEBUG: setDebug: JavaMail version 1.3.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.AuthenticationFailedException
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at test.SendMailServlet.sendMail(SendMailServlet.java:59)
at test.SendMailServlet.main(SendMailServlet.java:81)Sangyesh wrote:
In my application,we already implemented it so we cant go for javamail.That does not make sense. Your 'implementation' does not work so you have not yet fully 'implemented' it. Using Javamail takes about 4 lines of code to do what you have done so far and it will work.
Please suggest me regarding this,so that I can go ahead and resolve it.Use the Javamail API. -
How to forward and reply using java mail?
Im new to java mail...
Can anybody give me a detailed examples for
1. forwarding a mail
2. Replying to mail
from javamail?
thanks in advance
sandhyaDetailed? Not necessary. You have to create a new message and send it, that's all. Note that the Message has a reply() method that helps you to do that.
-
Problems while sending mail using java mail..help...
Hello all,
I am new to Java Mail...
Below is my first program...
Can anybody tell what's wrong in it..??
Thanks in advance....
------------------------------------------------------start--------------------
package test;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Send
public Send()
public void send()
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props=new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(props,new MyAuthenticator());
session.setDebug(true);
MimeMessage message=new MimeMessage(session);
try
message.setContent("Hello ...","text/plain");
message.setSubject("Test mail...plz don't ignore..");
Address to=new InternetAddress("[email protected]");
Address from=new InternetAddress("[email protected]");
Address replyTo=new InternetAddress("[email protected]");
message.setFrom(from);
message.setReplyTo(new Address[]{replyTo});
message.setRecipient(RecipientType.TO,to);
Transport.send(message);
} catch (AddressException e)
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchProviderException e)
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e)
// TODO Auto-generated catch block
e.printStackTrace();
public static void main(String[] args)
new Send().send();
class MyAuthenticator extends Authenticator
MyAuthenticator()
super();
protected PasswordAuthentication getPasswordAuthentication()
return new PasswordAuthentication("[email protected]", "*******");
--------------------------------------------end--------------
here is the output.....
DEBUG: setDebug: JavaMail version 1.3.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
220 mx.gmail.com ESMTP 16sm2443823wrl
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
EHLO jijo
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "20971520"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
530 5.7.0 Must issue a STARTTLS command first
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at test.Send.send(Send.java:50)
at test.Send.main(Send.java:68)
QUIT
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1275)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:895)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:524)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at test.Send.send(Send.java:50)
at test.Send.main(Send.java:68)
Can any body help me..??
Thanks and Regards
Jijo vincentHi All,
I am new to javax.mail.
I have attached my code and also error here...
can anyone help to resolve the error?
Code:
public class MailExample {
public static void main(String args[]) {
try {
String host = "localhost"; //args[0];
String from = "[email protected]"; //args[1];
// String to = "[email protected]";//args[2];
String to = "[email protected]";//args[2];
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.starttls.enable","true");
//props.put("mail.smtp.auth","true");
// 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(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
Transport.send(message);
catch(AddressException ae){
ae.printStackTrace();
}catch (MessagingException e)
// TODO Auto-generated catch block
e.printStackTrace();
Error:
DEBUG: setDebug: JavaMail version 1.3.3ea
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 "localhost", port 25, isSSL false
220 localhost
DEBUG SMTP: connected to host "localhost", port: 25
EHLO HDCHCTDAM33726
250-localhost
250 HELP
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 [email protected] Address Okay
RCPT TO:<[email protected]>
250 [email protected] Address Okay
DEBUG SMTP: Verified Addresses
DEBUG SMTP: [email protected]
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Message-ID: <10736847.01125315340863.JavaMail.sangeetham@HDCHCTDAM33726>
From: [email protected]
To: [email protected]
Subject: Hello JavaMail
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Welcome to JavaMail
com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)550 Invalid recipient: [email protected]
com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid recipient: [email protected]
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1160)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:538)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at org.worldbank.webmfr.util.MailExample.main(MailExample.java:55)
QUIT
Maybe you are looking for
-
I'm using DB Adapter from BPEL (and/or ESB), I've to update an orcl database and a ms sql server. I would like to use xa transactions. As long as I've the db adapter provided with soa suite 10.1.3.1 .0 supports global xa transactions via JCA 1.5 XA C
-
I am attempting to install Oracle DB RAC Grid Infrastructure 11gR2 on Solaris 10 Containers and am getting ASM PRVF-5150 error. After doing some search internally/externally, I found something like: .." the prerequisite check for Oracle ASM devices r
-
hello, Can i save the JTable's data in binary and reload them? give me some suggestions please Now i save the JTable's data as txt format,but i want to save a password's MD5 result before them(its format is binary).i want to save them in one format,h
-
Properties lost when widget is updated
I have created a simple widget using the Widget Factory. I've entered some Properties in Captivate and it works fine. However, after updating the widget in Flash and then clicking Update widget in Captivate, my Properties are gone (although the chang
-
Editor has stopped working: how do I restore it?
Up until this morning, SQL Developer was working fine, I'm quite pleased with it overall. This morning, however, I fired it up and opened a query window and discovered that the backspace, delete, enter and arrow keys no longer work. The only thing I