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.Sivaraman
Hello,
<p>Here is a Form sample.</p>
Francois
Similar Messages
-
How do I Send HTML formatted email using class in javax.mail pkg
How do I Send HTML formatted email using javax.mail pkg class ?i mean is thr any class available in this package to do this ?
Please see
http://javaalmanac.com/egs/javax.mail/SendApp.html
for Quintessential Program to Send E-Mail.
Then substitute line
msg.setText(content);
/with this one
msg.setContent( content , "text/html");
it should do in simplest form. -
How do I mix text and Html format in a java mail?
How do I mix text and Html format in a java mail? some part I want to keep the text format, the other part I want to use Html functions(like fond, color, etc)
You don't mix them. Pick one or the other.
However if you want to have a text version and an HTML version, so that mail readers that don't handle HTML can see regular text instead, then you could produce a "multipart/alternative" message. There's an explanation of how to do that in this article:
http://www-128.ibm.com/developerworks/java/library/x-xmlist2/ -
How to do SAVE AS DRAFT using java mail api
Hello,
I want to know how to do SAVE AS DRAFT using Java mail Api.
thanksHello,
I want to know how to do SAVE AS DRAFT using Java
mail Api.
thanksI don't think you can. That sounds like a feature of a mail client app itself. The Java mail API is for when you're ready to actually send the thing. Saving drafts is storing them somewhere like you would any other data; nothing to do with the mail API. -
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 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. -
Want to send PDF as attachement using Java Mail
HI,
I am using Java mail API for sending PDF as attachment. Here is my sample code
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler("String data for PDF using iText", "text/plain" ));
I am generating String for PDF file using iTEXT but I am unable to find out mimetype for passing into DataHandler as second paramete.
Any idea?
Thanks
ShaileshDon't convert the data to String. It isn't text so
you'll damage the binary content by doing that. In
the "demos" directory of your JavaMail download
you'll find a ByteArrayDataSource class you can use
instead of a FileDataSource. Yes, this worked for me. I create the pdf in memory as as StringBuffer and I just changed the code from
messageBodyPart.setDataHandler(new DataHandler(pdf.toString(), "application/pdf"));
to
messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf.toString(), "application/pdf")));
and it worked.
Thanks a lot for your help,
Dennis -
How to SEND HTML formatted mail??
How do I put HTML formatted text into an email I want to SEND? -- "Paste as HTML" in edit menu is dimmed, and I can't get it to un-dim... I want to paste formatted text from an HTML editor into an email... can I do this with Mail, or do I need some other app to do this?
AHHHH
What you can do to make HTML for Apple Mail is to make it in an HTML editor, open it with Safari use CMD+i - a new mail message will appear in a moment with the web page in the email body.
You can't do any major editing in Mail, you'll have to go back to the HTML file. But it works.
You can also use Copy (from a web page) and then (Edit) Paste as HTML (that what Paste as HTML is for, not for creating HTML email). You can also user Paste as HTML to copy/paste a HTML email you receive or part of a HTML email. -
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 -
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. -
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 -
Problems in Sending mails using java mail
hi all,
heres my piece of code-
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class SendEmail
public static void main(String[] args)
System.out.println(args.length);
if (args.length != 6)
System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");
System.exit(1);System.out.println("jj"+args.length);
SendEmail m=new SendEmail();
m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);
public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)
boolean debug = false; // change to get more information
String msgText2 = "multipart message";
boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",smtphost);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.sendpartial", "true");
Authenticator loAuthenticator = new SMTPAuthenticator();
System.out.println("f");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, loAuthenticator );
session.setDebug(debug);
System.out.println("ff");
//System.out.println( loAuthenticator);
try
// create a message
Message msg = new MimeMessage(session);
// set the from
InternetAddress from = new InternetAddress(emailfrom);
msg.setFrom(from);
InternetAddress[] address =
new InternetAddress(emailto)
//InternetAddress ad=new InternetAddress(session);
//System.out.println(ad.getLocalAddress());
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(msgSubject);
if(!sendmultipart)
// send a plain text message
msg.setContent(msgText, "text/plain");
else
// send a multipart message// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(msgText, "text/plain");
// create and fill the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent(msgText2, "text/plain");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport transport = session.getTransport("smtp");
transport.connect(smtphost,"[email protected]","xyz");
msg.saveChanges();
//transport.sendMessage(msg,msg.getAllRecipients());
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
catch(MessagingException mex)
mex.printStackTrace();
return "Email sent to " + emailto;
class SMTPAuthenticator extends Authenticator
public PasswordAuthentication getPasswordAuthentication()
String username = "[email protected]";
String password = "xyz";
return new PasswordAuthentication(username, password);
i get the following errors-
SmtpSendFailedException:550 Invalid Recipient
Sometimes the mail gets send but sometimes it doesnt (while sending it to yahoo)..
i guess there is some firewall problem..
can somebody help me please.
thanksHello. I don't know if this will help you much but just reading the posts there might be something wrong with the information that is being sent to your SMTP host. You might make sure that the string that you are sending doesn't have extra characters attached to it or that a timeout is not occuring during the transfer of your username/password information. Sometimes the '@' gets translated into something else.
A 550 error usually indicates that the mail server didn't recived a valid user on the system, this came into play I believe when people start abusing SMTP to SPAM a server using everything under the sun...so filters were put in place i.e. If you are not a Qualified Domain Name registered mailserver and someone has a filter in place your message will go kersplat because forwarding is no longer being allowed. Yopu might try a diffrent tactic.
1. you might trim your strings.
2. build strings in a connect method so that its a bit less amateur code.
public void connect() {
// Display connect dialog.
ConnectDialog dialog = new ConnectDialog(this);
dialog.show();
// Build connection URL from connect dialog settings.
StringBuffer connectionUrl = new StringBuffer();
connectionUrl.append(dialog.getType() + "://");
connectionUrl.append(dialog.getUsername() + ":");
connectionUrl.append(dialog.getPassword() + "@");
connectionUrl.append(dialog.getServer() + "/");3. Make absolutely certain that the SMTP server you are sending from is registered and qualified in your code. Meaning you can't use a bogus MTA(mail trasport agent) or you get bounced.
private void sendMessage(int type, Message message) {
// Display message dialog to get message values.
MessageDialog dialog;
try {
dialog = new MessageDialog(this, type, message);
if (!dialog.display()) {
// Return if dialog was cancelled.
return;
} catch (Exception e) {
showError("Unable to send message.", false);
return;
try {
// Create a new message with values from dialog.
Message newMessage = new MimeMessage(session);
newMessage.setFrom(new InternetAddress(dialog.getFrom()));
newMessage.setRecipient(Message.RecipientType.TO,
new InternetAddress(dialog.getTo()));
newMessage.setSubject(dialog.getSubject());
newMessage.setSentDate(new Date());
newMessage.setText(dialog.getContent());
// Send new message.
Transport.send(newMessage);
} catch (Exception e) {
showError("Unable to send message.", false);
}Lastly, if you are writing a SPAM client, you should go to your dos prompt and type format c: (j/k)
now the disclaimer. The code published is not mine it was a piece of an example that I got from a brillient book by Herbert Schildt and James Holmes who I would love to be able to chat with since the work they do is absolutely perfect. You might check it out from your Local Library the ISBN is 0-07-222971-3 they have a whole section just on JavaMail.
Well hope that gets you started in the right direction, I would read the ISO standards published for SMTP, you might get a better grip on the error codes that are bound to come up. -
How to handle an email message using java mail
I am facing the problem in handling html mails embedded with images. Can anyone give me some idea about handling these contents or can I convert whole mail content to an mht file? If yes, then how to convert that mail content to an mht file.
You have no idea? Then look in your JavaMail download and you will find several sample programs that you can use to get started. It would also help to read the JavaMail FAQ (Google will find it easily for you).
-
How to send results to actionscript using java
Hi,
I do RPC using HttpService.
In my situation, I need to send results from Java code to
Flex Action script. I have defined a Java Servlet receiving data
from Flex application, then it processes with the data, finally the
Servlet is supposed to send some feedbacks to the client(Flex).
My question is that how can I define codes in doPost() method
that the following function will get "result" from the Java side.
public static function httpResult(event:ResultEvent):void
var result:Object = event.result;
//Do something with the result.
if (result.toString() == "success")
resultMessage.text = "Login Success";
resultMessage.text = "Invalid User";
}Hi,
Try this: If you are sending a simple text as "sucess" or
"error" after doing some process in the servlet..
set your content type to "text/plain" and simply
println(<data to be sent>);
In the flex application, get the result text that the servlet
send using:
resultString = String(httpUrl.lastResult);
where httpUrl is the id of the HTTPService. Now you can
compare what the servlet send by:
if(resultString=="sucess") {
Hope this solves your problem :)
Regards,
-- Abdel Olakara
http://olakara.googlepages.com
http://technopaper.blogspot.com
Maybe you are looking for
-
Can/t scan documents from HP OJ 6500A plus
Ever since I installed McAfee, I can no longer scan a document from my HP 6500A Plus to my Dell Inspiron desktop computer. I keep getting the message "Scanner communication cannot be establisheed".
-
To concatenate Header and Footer , You have to use Joiner Transformation and Join with a Dummy Condition. In first there will be columns like file name, date , time and in second there will be column like trailer record count and amount , so after
-
WHAT IS THE BEST EXTERNAL HARD DRIVE????
I am urgently in need of information about the External Hardrives that are very reliable. I had a very bad and serious experience with my new hardd rive wich I bought recently.
-
Spreadsheet component shrinks to size of a Dice
Hello, I have a dynamic dashboard using spread sheet component. During the run time I have seen the spreadsheet component shrinks to a very small size, I could say it shrinks to size of a dice and this issue is very intermittent. FYI: I am having th
-
Iterate through XML tags of file (CS5)
Hello! I'd like to iterate through an XML file, but I am not sure how to do this, since the import is mostly done automatically. This is how I load and import the file: var f = new File('~/Desktop/test.xml'); app.activeDocument.importXML(f); But ho