How to use setContent() in javamail

I want to send a mail through Jsp page. My code for to do this is given below.It sends the mail but the problem is that it prints the Html code as it is in the text that is send through mail.. for example if i write message.setText("testing<br>hello"); than it prints message<br>hello as mail text instead of taking the break after testing.... pl reply soon...
<%@ page import="javax.mail.*, javax.mail.internet.*, java.io.*, javax.mail.event.*, java.net.*, java.util.*" %>
<%
Properties props=new Properties();
props.put("mail.smtp.host","mail.infobase.in");
          Session session1 = Session.getDefaultInstance(props,null);
MimeMessage message =new MimeMessage(session1);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients
(Message.RecipientType.TO,InternetAddress.parse("[email protected]",false));
message.setSubject("hello");
message.setText("testing<br>hello");
Transport.send(message);
out.println("mail has been sent");
%>

In JavaMail 1.4:
http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimeMessage.html#setText%28java.lang.String,%20java.lang.String,%20java.lang.String%29
Is there something about the way that's written that makes it hard to understand?
Again, in earlier versions of JavaMail this was more difficult.
The key line from the sendhtml.java demo program (were you
unable to find it?) is:
msg.setDataHandler(new DataHandler(
                new ByteArrayDataSource(sb.toString(), "text/html")));

Similar Messages

  • How to use gmail with JavaMail

    JavaMail 1.4 is capable of sending and reading messages using gmail.
    All that's required is to properly configure JavaMail. I'll
    illustrate the proper configuration using the demo programs that
    come with JavaMail - msgshow.java and smtpsend.java.
    Let's assume your gmail username is "[email protected]" and your
    password is "passwd".
    To read mail from your gmail Inbox, invoke msgshow as follows:
    java msgshow -D -T pop3s -H pop.gmail.com -U user -P passwdBy reading the msgshow.java source code, you can see how these
    command line arguments are used in the JavaMail API. You should
    first try using msgshow as shown above, and once that's working
    move on to writing and configuring your own program to use gmail.
    To send a message through gmail, invoke smtpsend as follows:
    java -Dmail.smtp.port=587 -Dmail.smtp.starttls.enable=true smtpsend
            -d -M smtp.gmail.com -U user -P passwd -A [email protected](Note that I split the command over two lines for display, but you
    should type it on one line.)
    The smtpsend command will prompt for a subject and message body text.
    End the message body with ^D on UNIX or ^Z on Windows.
    Gmail requires the use of the STARTTLS command, and requires a
    non-standard port, which the smtpsend program doesn't have command
    line options to select so we set them as System properties on the
    java command. The smtpsend.java program uses the System properties
    when creating the JavaMail Session, so the properties set on the
    command line will be available to the JavaMail Session.
    Again, you can read the smtpsend.java source code to see how the
    command line arguments are used in the JavaMail API. There is,
    of course, more than one way to use the JavaMail API to accomplish
    the same goal. This should help you understand the essential
    configuration parameters necessary to use gmail.
    And no, I won't send you an invitation to gmail. Sorry.

    I notice that it's possible to have sticky posts in these forums. See
    http://forum.java.sun.com/forum.jspa?forumID=534
    the Concurrency forum for an example. Posting a link to the FAQ in a sticky post might reduce the number of FAQs asked here by maybe 1%? Or posts like this one might do well as a sticky?

  • How to use Javamail for accessing additional mailboxes -IMAP, Exchange 2010

    hi,
    I want to access a shared mailbox (NOT FOLDER) via Javamail API (1.4.5) using IMAP(s) with plain logon. The mailserver is a Exchange Server 2010.
    User: user1 ([email protected])
    pwd: xxxx
    shared mailbox: [email protected]
    Properties:
    mail.imaps.socketFactory.port = 993
    mail.imaps.starttls.enable = true
    mail.imaps.socketFactory.class = javax.net.ssl.SSLSocketFactory
    mail.imaps.socketFactory.fallback = false
    username = [email protected]
    password = xxxx
    I´ve managed to get access to the user1 - mailbox:
    Session session = Session.getInstance(properties, new ExchangeAuthenticator(username, password));
    session.setDebug(true);
    Store store = session.getStore("imaps");
    store.connect(imapHost, username, password);
    --> this works just fine! But now i want to access the additional mailbox by changing the login-String:
    [email protected]/shared_MB (user@domain/additional_MB)
    --> unfortunately I´m getting an "NO AUTHENTICATE" message:
    DEBUG: setDebug: JavaMail version 1.4.5
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,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 "host.domain.com", port 993, isSSL true
    * OK The Microsoft Exchange IMAP4 service is ready.
    A0 CAPABILITY
    * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN UIDPLUS CHILDREN IDLE NAMESPACE LITERAL+
    A0 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: NTLM
    DEBUG IMAP: AUTH: GSSAPI
    DEBUG IMAP: AUTH: PLAIN
    DEBUG: protocolConnect login, host=host.domain.com, [email protected]/shared_MB, password=<non-null>
    DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
    DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 NO AUTHENTICATE failed.
    javax.mail.AuthenticationFailedException: AUTHENTICATE failed.
    I was able to get access with Thunderbird and also with the Exchange OWA-Client, so I think there is something missing in my code...
    or is it just impossible to get access to a different mailbox using javamail and plain-auth?
    Thank you in advance.

    Thanks bshannon, that was a great idea!
    I haven´t found an solution yet, but I have maybe identified the real problem:
    Here is some interessting Thunderbird - Logging stuff:
    744[7161040]: try to log in
    744[7161040]: IMAP auth: server caps 0x1187235, pref 0x1006, failed 0x0, avail caps 0x1004
    744[7161040]: (GSSAPI = 0x1000000, CRAM = 0x20000, NTLM = 0x100000, MSN = 0x200000, PLAIN = 0x1000, LOGIN = 0x2, old-style IMAP login = 0x4)auth external IMAP login = 0x20000000
    744[7161040]: trying auth method 0x1000
    744[7161040]: got new password
    744[7161040]: IMAP: trying auth method 0x1000
    744[7161040]: PLAIN auth
    744[7161040]: 7082000:xmail.domain.com:NA:SendData: 2 authenticate plain
    744[7161040]: ReadNextLine [stream=7ec9e88 nb=3 needmore=0]
    744[7161040]: 7082000:xmail.domain.com:NA:CreateNewLineFromSocket: +
    744[7161040]: 7082000:xmail.domain.com:NA:SendData: Logging suppressed for this command (it probably contained authentication information)
    744[7161040]: ReadNextLine [stream=7ec9e88 nb=27 needmore=0]
    744[7161040]: 7082000:xmail.domain.com:NA:CreateNewLineFromSocket: 2 NO AUTHENTICATE failed.
    744[7161040]: authlogin failed
    744[7161040]: marking auth method 0x1000 failed
    ---> okay, so PLAIN AUTH is failing.....
    744[7161040]: IMAP auth: server caps 0x1187235, pref 0x1006, failed 0x1000, avail caps 0x4
    744[7161040]: (GSSAPI = 0x1000000, CRAM = 0x20000, NTLM = 0x100000, MSN = 0x200000, PLAIN = 0x1000, LOGIN = 0x2, old-style IMAP login = 0x4)auth external IMAP login = 0x20000000
    744[7161040]: trying auth method 0x4
    744[7161040]: got new password
    744[7161040]: IMAP: trying auth method 0x4
    744[7161040]: old-style auth
    744[7161040]: 7082000:xmail.xmail.domain.com:NA:SendData: Logging suppressed for this command (it probably contained authentication information)
    744[7161040]: ReadNextLine [stream=7ec9e88 nb=23 needmore=0]
    744[7161040]: 7082000:xmail.domain.com:NA:CreateNewLineFromSocket: 4 OK LOGIN completed.
    744[7161040]: login succeeded
    --> okay, so Thunderbird is using "old-style IMAP login" and is successful.
    Unfortunately I have no idea what that actually means or how to use it in Javamail (is it even supported?). Any suggestions?

  • How to use JavaMail 1.4 with Oracle Application Server 10g (9.0.4.0.0)

    Hi all,
    I'd like to know if it's possible and how to use JavaMail 1.4 with Oracle Application Server 10g (9.0.4.0.0), Windows version.
    With the following code, I can see that the mail.jar used by the server is the one included in the jdk installation :
    // I'm testing InternetAddress.class because I want to use commons-email-1.2.jar that requires mail.jar 1.4 (or higher) and activation.jar 1.1 (or higher)
    // and I know that inside the commons-email-1.2.jar file, I need to call the InternetAddress.validate() method that throws a java.lang.NoSuchMethodError: javax.mail.internet.InternetAddress.validate()V if it is used with mail.jar 1.2.
    Class cls = javax.mail.internet.InternetAddress.class;
    java.security.ProtectionDomain pDomain = cls.getProtectionDomain();
    java.security.CodeSource cSource = pDomain.getCodeSource();
    java.net.URL location = cSource.getLocation();
    System.out.println(location.toString());
    This code returns : file:/C:/oracle/app/jdk/jre/lib/ext/mail.jar and this mail.jar file has an implementation version number: 1.2
    - I've tried to include my own mail.jar (1.4.2) and activation.jar (1.1.1) files in the war file that I deploy, but it doesn't work (the server still uses the same mail.jar 1.2)
    - I've tried to put the mail.jar (1.4.2) and activation.jar (1.1.1) files in the applib directory of my OC4J instance, but it doesn't work (the server still uses the same mail.jar 1.2)
    - I know that a patch exists : I've read the following document: How to Make Libraries such as mail.jar and activation.jar Swappable ? [ID 552432.1]
    This article talks about the Patch 6514136, but this patch only applies to : Oracle Containers for J2EE - Version: 10.1.3.3.0
    Can you please help me ?
    Thanks in advance for your answers,
    Laurent

    I strongly suggest to upgrade to AS 10.1.3 to get this.
    Think of future support of AS 9.0.4. You will get not critical patch updates anymore.
    --olaf                                                                                                                                                                                                                                                                                                               

  • How to use JavaMail

    Hi,
    I want to send an email through a servlet using the
    javaMail API. I haven't used it before and have no idea on how to use it. I used the oreilly classes in the past but now I want to send attachments. Could anybody help me?
    Thanks in advance,

    This is a sample
    MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(filepath and name);
    mbp2.setDataHandler(new DataHandler(fds));
    mbp2.setFileName(fds.getName());
    mp.addBodyPart(mbp2);

  • How to use JavaMail to receive incomming email?

    Hello,
    I am a year 3 student and doing a final year project about web hosting.
    I want to know how to use JavaMail to receive and treat the incomming email. It means that the incoming email how to process and store the "message" in the recipient "folder" in the "store" class.
    If you have any optinions or examples or suggestion, please contact me.
    Thank you for your attention....

    First, it would be better to post questions about JavaMail in the JavaMail forum and not in the JSP forum.
    Second, the JavaMail download comes with a set of examples, including some that cover exactly what you ask.

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • How to send an Email using SMTPSSLTranport of JavaMail

    Hi,
    Provide me any sample code to send the mail using SMTPSSLTransport of JavaMail.
    Thanks,Sujata.

    is it something like that you want :
    (you can fin a similar answer in many places, even in this forum...)
    // mail session;
                   Session mailSession;
                   // set properties for appropriate server
                   Properties props = new Properties();               
                   props.put("mail.smtp.host", strServer);               
                   props.put("mail.smtp.starttls.enable","true");
                   props.put("mail.smtp.auth", "true");                    
                   props.put("mail.smtp.socketFactory.port", "465");
                   props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                   props.put("mail.smtp.socketFactory.fallback", "false");
                // uncomment for debug
                // props.put("mail.debug", "true");
                mailSession = Session.getInstance(props, new Authenticator() {
                     protected PasswordAuthentication getPasswordAuthentication() {
                          return new PasswordAuthentication(strLogin, strPassword);}});          
                // prepare message
                Message message= new MimeMessage(mailSession);           
                InternetAddress[] arrToAddress = {new InternetAddress(strTo)};
                message.setRecipients(Message.RecipientType.TO, arrToAddress);
                InternetAddress fromAddress = new InternetAddress(strFrom);
                message.setFrom( fromAddress );
                message.setSubject( strSubject);          
                message.setText( strMessage );    
                message.setSentDate((Calendar.getInstance()).getTime());
                message.setHeader(Constants.PROXYMAIL_ERROR_OK, "JavaMail");
                // Send our mail message                               
                Transport.send(message);    

  • Using JSF and JavaMail to send Automated Email

    Hi All,
    Can any one please suggest I can use JSF and JavaMail to send automated email messages i.e after a person has successfully completed a form , a message is sent to his/her email address confirming that he has succesfully registered or completed a form. I have succesfull implemeted the use of javamail for sending email meassages in a JSF web application but cant seem to figure out how i can achieve automated sending of emails in JSF. Please any ideas, tutorials or source code would be very much appreciated.
    Thanks.

    I don't understand your problem:
    You have already been able to send e-mails from a JSF webapplication, but you are not capable of sending e-mails from a JSF webapplication?!
    Automated sending of e-mails will be exactly the same as non-automated.

  • How to use weblogic on jdk 5?

    Does anyone know, how to use weblogic and jdk 5?

    Supported on version 9.0 Beta, only.
    http://e-docs.bea.com/platform/suppconfigs/configs90/90_over/overview.html#1122259
    Bill
    "Fauzi Mubarok" <[email protected]> wrote in message
    news:2966888.1105597574948.JavaMail.root@jserv5...
    Does anyone know, how to use weblogic and jdk 5?

  • How to use one email adress for multiple recipients

    Hello,
    I'd like to know how to use one email adress for multiple recipients. 
    this would be very useful or projects. for example;
    if i send one mail to [email protected], all people in this project get an email.
    I will add the people in this project myself. 
    I know it is possible, but I don't know how to do it ;-)
    please help me! 

    Hope this help.
    _http://technet.microsoft.com/en-us/library/cc164331(v=exchg.65) .aspx

  • Can't figure out how to use home sharing

    Since the latest couple iTunes updates, my family and I can not figure out how to use home sharing. Everyone in our household has their own iTunes, and for a long time we would just share our music through home sharing. But with the updates, so much has changed that we can no longer figure out how to use it.
    I have a lot of purchased albums on another laptop in the house, that im trying to move it all over to my own iTunes, and I have spent a long time searching the internet, and everything. And I just can't figure out how to do it. So.... how does it work now? I would really like to get these albums from my moms iTunes, onto mine. I would hate to have to buy them all over again.
    If anyone is able to help me out here, that would be great! Thanks!

    The problem im having is that after I am in another library through home sharing, I can't figure out how to select an album and import it to my library. They used to have it set up so that you just highlight all of the songs you want, and then all you had to do was click import. Now I don't even see an import button, or anything else like it. So im lost... I don't know if it's something im doing wrong, or if our home sharing system just isn't working properly.
    Thanks for the help.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • How to use airport time capsule with multiple computers?

    I'm sure there are some thread about this but i couldn't find it... so sorry for that but hear me out! =)
    I bought the AirPort Time Capsule to back up my MBP
    And so i did.
    then i thought "let give this one a fresh start" so i erased all of it with the disk utility and re-installed the MBP from the recovery disk.
    I dont want all of the stuff i backed up just a few files and some pictures so i brought that back.. so far so good.
    Now i want to do a new back up of my MBP so i open time machine settings, pick the drive on the time capsule and then "Choose" i wait for the beck up to begin, and then it fails.  It says (sorry for my bad english, im swedish haha) "the mount /Volume/Data-1/StiflersMBP.sparsebundle is already in use for back up.
    this is what i want:
    i want the "StiflersMBP.sparsebundle" to just be so i can get some stuf when i need them. it's never to be erased.
    i want to make a new back up of my MBP as if it's a second computer...
    so guys and girls, what is the easiest and best solution?
    Best regards!

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How to use multiple ipods on one account

    I have an Ipod classic and just bought my sons two nano's how do I use these on the same account without changing my account info?

    Take a look here:
    How to use multiple iPods with one computer
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Discussions page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums, in the User Tips Library and in the Apple Knowledge Base before you post a question.
    Regards.

Maybe you are looking for

  • Two-sided printing with Epson Workforce 630

    I bought a new iMac a few months ago and got the Epson WorkForce 630 printer at the same time. However, I can't figure out how to do duplex (two-sided) printing. I've searched around, and it looks like this feature may not be supported for the Mac. N

  • Runtime Error # DBIF_RSQL_INVALID_RSQL for large size BOMs

    Hi All, I am facing problem running a custom report for Routing summary. When Executing the report gives the above runtime error. ShrtText: Error in RSQL module of database interface.  Error analysis : An exception occurred. This exception is dealt w

  • ITunes 7 and Nano No-No

    My system is completely in error since the update of iTunes 7. The Nano mounts in the finder and i can start iTunes 7 but when i doubleclick a file on the Nano iTunes hangs, system hangs everything very awkward. Connected to my powerbook (itunes 6.04

  • Numeric Value rounding problems in Materialized Views

    All numeric values are getting rounded in the materialized views. Is there any solution for this? Any help is greatly appreciated... Thanks, Satya

  • Finder crashes every 60 seconds

    Hi there I've been going lots of googling the past couple of days but haven't turned up a solution yet... Finder crashes and relaunches every minute or so. "Remove the .plugin files and log out/in again" I hear you say. Done, no joy. Tried removing c