How to Send Html Email using JavaMail?

I want to send email message body as html.
as some news sites send.What will easiest way of doing that?

oops!!!
Sorry there is one more thing in it the ByteArrayDataSource class. I am posting the code in the class here. Compile it in a separate class.
class ByteArrayDataSource implements DataSource
    private byte[] data;     // data
    private String type;     // content-type
    /* Create a DataSource from an input stream */
    public ByteArrayDataSource(InputStream is, String type)
        this.type = type;
        try
            ByteArrayOutputStream os = new ByteArrayOutputStream();
              int ch;
              while ((ch = is.read()) != -1)
            // XXX - must be made more efficient by
             // doing buffered reads, rather than one byte reads
             os.write(ch);
              data = os.toByteArray();
        } catch (IOException ioex) { }
    /* Create a DataSource from a byte array */
    public ByteArrayDataSource(byte[] data, String type)
        this.data = data;
          this.type = type;
    /* Create a DataSource from a String */
    public ByteArrayDataSource(String data, String type)
          try
         // Assumption that the string contains only ASCII
         // characters!  Otherwise just pass a charset into this
         // constructor and use it in getBytes()
         this.data = data.getBytes("iso-8859-1");
          catch (UnsupportedEncodingException uex)
          this.type = type;
     * Return an InputStream for the data.
     * Note - a new stream must be returned each time.
    public InputStream getInputStream() throws IOException
          if (data == null)
              throw new IOException("no data");
          return new ByteArrayInputStream(data);
    public OutputStream getOutputStream() throws IOException
          throw new IOException("cannot do this");
    public String getContentType()
        return type;
    public String getName()
        return "dummy";
}hope this will help
best wishes
khuda hafiz

Similar Messages

  • How to send secure email using JavaMail

    Hi, anyone out there know how to send secure email using Java Mail? Greately appreciated.

    For starters, if you have not already done so, read about it in the JavaMail design specifications.
    Search for Message Security in the said document.

  • How to send HTML email using alert framework? Kindly help!

    Hi Experts,
          I am using alert framework (alert category) to send email. In the email message I want to use HTML content along with some hyperlinks.
         How can I do this?
         kindly help!
    Thanks
    Gopal
    Message was edited by:
            gopalkrishna baliga

    Hi,
    To send hyper links, you can add the links in the FollowUp Activity.
    The content of the mail from the alert framework will be a text mail.
    One option would be to check in your SCOT settings if it would be possible to set the Content Type as TEXT/HTML . If yes, then maybe this should be possible.
    Regards
    Bhavesh

  • How to send html email made in dreamweaver

    how to send html email made in dreamweaver

    Make sure you upload all of the images used in your email to a server you control. Then, change your image paths to point to those uploaded images with absolute links.
    You will get marked as spam if you attempt to send images as attachments to a large list of recipients and most email clients won't download images to begin with, so make sure your html email makes sense with broken pictures.
    CSS support is spotty across email clients, if you use css, make sure it's inline, not embedded in the <head> or externally linked in the <head>. Some email clients strip out the <head> section entirely.
    Basically, you need to design your html email as if you haven't moved out of the 90's yet, as far as web design is concerned, in order to get maximum cross client compatibility.
    Then, when you're ready, I would suggest using a service like www.icontact.com or www.constantcontact.com if your subscriber list is anywhere over 100 or so recipients.

  • How to send CC email using SO_DOCUMENT_SEND_API1

    Hi,
       How to send CC email using SO_DOCUMENT_SEND_API1.  Any sample code is very much appreciated.
    Cheers

    Please check In this function there is a flag in RECEIVERS table for sending mail as COPY or BLIND COPY

  • 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 send an email using XML Publisher

    Can any body help me how to send an email using XML Publisher.
    Regards,
    Suresh

    Sorry ,
    when a http://blogs.oracle.com/xmlpublisher/newsItems/departments/documentDelivery
    this it show this not answer the question.
    Thanks
    Welcome to Oracle Blogs
    Welcome to the Oracle blogging community, where Oracle executives, employees, and non-employees exchange views about customer requirements and best practices.
    We're sorry, the weblog you requested cannot be accessed.
    - You may not have the necessary permission for access the weblog.
    - This weblog does not exist.
    You may wish to try again using one of the tools below.
    - Check the URL and contact your System Administrator for access.
    - Or click here to go back to Oracle Blogs homepage.
    Powered by
    Movable Type and Oracle
    The views expressed on this blog are my own and do not necessarily reflect the views of Oracle. Terms of Use

  • How to send HTML email to End User using OOTB email processs?

    Hi,
    We are using OOTB Send email process to send email to end user.
    Templates has been created inside /etc/workflow/ProjectName/email folder.
    Its working properly for plain text email.but for html template ,It send the email with html tags.
    Any pointer on how to write html template for OOTB email process and activate email type as html ?
    Thanks
    Deepika

    Thanks Sham..
    I am able to send HTML email following above link.
    The problem i am facing is,When i am deploying the code through crxde.Code is working fine.
    But using maven deploy..Bundle get activated ..But at line:
    messageGateway = this.messageGatewayService.getGateway(HtmlEmail.class);
    ,it gives null Pointer exception.
    Any pointer,why its not working from maven deployment.
    Regards
    Deepika

  • How to send html email notification in bpel

    hi gurus,
    i want to send html email notification from bpel.
    before, i already successful send html email with attachment, but when i send an email without attachment, then the body message will turn into a plain text.
    as i check from the email accepted, email with attachment will have a mime type "text/html" but if no attachment then it will be "text/plain"
    from the bpel configuration, by default the mime type already set to "text/html; charset=UTF-8", below is the sample configuration in my bpel process
    [quote]
    <copy>
                                    <from>string('text/html; charset=UTF-8')</from>
                                    <to variable="varNotificationReq"
                                        part="EmailPayload">
                                        <query>ns10:Content/ns10:MimeType</query>
                                    </to>
                                </copy>
    [/quote]
    i think this suppose to be a easy configuration, but i'm not sure whether i miss something in configuration the email process or this is a bugs in bpel.
    environment:
    linux
    jdev 11.1.1.6
    do u guys ever facing a same problem or have a solution to this ? please throw some light.
    thanks
    ===
    update, i found a temporary solutions.
    so i add a attachment from the process design, and then i change it from the source.
    [quote]
    <copy>
                                    <from>
                                        <literal>
                                            <Content xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService">
                                                <MimeType xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService">multipart/alternative</MimeType>
                                                <ContentBody xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService">
                                                    <MultiPart xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService">
                                                        <BodyPart xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService">
                                                            <MimeType xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService"/>
                                                            <ContentBody xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService"/>
                                                            <BodyPartName xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService"/>
                                                        </BodyPart>                                            
                                                    </MultiPart>
                                                </ContentBody>
                                            </Content>
                                        </literal>
                                    </from>
                                    <to variable="varNotificationReq"
                                        part="EmailPayload">
                                        <query>ns10:Content</query>
                                    </to>
                                </copy>
    <copy>
                                    <from>string('text/html; charset=UTF-8')</from>
                                    <to variable="varNotificationReq"
                                        part="EmailPayload">
                                        <query>ns10:Content/ns10:ContentBody/ns10:MultiPart/ns10:BodyPart[1]/ns10:MimeType</query>
                                    </to>
                                </copy>
                                <copy>
                                    <from>string('your message')</from>
                                    <to variable="varNotificationReq"
                                        part="EmailPayload">
                                        <query>ns10:Content/ns10:ContentBody/ns10:MultiPart/ns10:BodyPart[1]/ns10:ContentBody</query>
                                    </to>
                                </copy>
    [/quote]
    make sure you put the mime type multipart/alternative into the email payload content. by default, when you add attachment, it will generate mime type multipart mixed automatically.
    if you don't change it to multipart/alternative, your email will show a attachment, but actually your email doesn't contain any attachment.
    and then for the message and mimetype make sure you have that ns10:bodypart, because this email already been set as a multipart email.
    when you add attachment, by default it will generate 2 body part, first one is for the body message and the second one is for the attachment. since i only want to use the body message only, then i have to erase the second bodypart
    with this workaround, i can send a html email without attachment perfectly.
    but i have to take note, when i updating the email process from process design, then the source will be generated again automatically, and the edited one will be replaced.
    thanks.

    Make sure you upload all of the images used in your email to a server you control. Then, change your image paths to point to those uploaded images with absolute links.
    You will get marked as spam if you attempt to send images as attachments to a large list of recipients and most email clients won't download images to begin with, so make sure your html email makes sense with broken pictures.
    CSS support is spotty across email clients, if you use css, make sure it's inline, not embedded in the <head> or externally linked in the <head>. Some email clients strip out the <head> section entirely.
    Basically, you need to design your html email as if you haven't moved out of the 90's yet, as far as web design is concerned, in order to get maximum cross client compatibility.
    Then, when you're ready, I would suggest using a service like www.icontact.com or www.constantcontact.com if your subscriber list is anywhere over 100 or so recipients.

  • How to format and send html email using utl_smtp

    Hi,
    I need to send email in the html format from within the database using utl_smtp. I am really not interested in creating os level file using "set markup html on spool on" and sending that as an html attachment. Can someone please give a code?
    1. Output of a select needs to be emailed (for example : select empid, name from emp, salary)
    2. Certian cells for example salary < 4800 needs to be higlighted in Red color
    3. I need to send email which is having more than 32767 characters (I can not use varchar2 field)
    I have reffered to following url on asktom:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1739411218448
    However it does not help.
    If someone has a sample code with any select from a table, it would be a great help.
    Regards
    Sudhanshu Bhandari

    There have been many very good threads on sending email using the UTL_SMTP on the forum including threads that deal with HTML formated mail.
    The basic process is to the same as with sending regular (non HTML) mail, but you add some additional headers to the mail message as well as additional formatting to the message body (e.g. HTML tags as needed).
    Specifically you need to add the two following headers:
    MIME-Version: 1.0
    Content-type: text/html

  • 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);    

  • How to send HTML email in Outlook

    How do I send a HTML email in Outlook 2003? I figured out how to do it in Outlook Express. I can't figure out how to open the place for entering the source code like OE. How do I do this.
    Yes, I have already posted the HTML onto a server.
    Yes, the CSS is in the HTML file.

    Don't use Outlook or Outlook Express for this.
    My recommendation is the same as Joe's.  Either use a dedicated bulk email software or a bulk email service like MailChimp, etc...
    If your list is especially large, and you attempt to send to a volume that's prohibited by your server or email service provider, you could be in violation of their anti-spamming rules.  You don't want that.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com
    Sorry Joe. Didn't mean to call you EagerBob.

  • Sending an Email using JavaMail from the Net Work of my company not workin

    Hi,
    If any body would reply to this issue as soon as possible..
    I have developed a simple java mail program which sends an email to gmail (smtp.gmail.com) and works fine at home , So when i sent the same
    from my office(at company) it did not work and exception was reported saying ...... could not connect to host .smtp.gmail.com... port .. .
    I think it's a network problem.
    So If any body has a suggestion ?
    If so can any body give a simple code for this issue.
    Regards,

    No, I don't mean the msgshow.java demo program. I mean the [JavaMail FAQ|http://java.sun.com/products/javamail/FAQ.html].
    In particular, the section about debugging connection problems and the section
    about connecting to Gmail.
    Find it yet?

  • Sending html email using utl_smtp

    (Oracle 8.1.7)
    I'm using the following procedure to send an HTML formatted e-mail. It sends email but I'm seeing in Outlook html code instead of formatted mail. (It sends text like :
    a bit of text
    --a1b2c3d4e3f2g1
    content-type: text/html;
    <html><head></head><body><B>HELLO </B></body></html>
    a1b2c3d4e3f2g1
    What can I solve this problem?
    Thanks in advance...
    its usage :
    html_email('smo@....','smo2@...','This is a subject','a bit of text', '<html><head></head><body><B>HELLO </B></body></html>', 'some hostname',25);
    CREATE OR REPLACE procedure html_email(
    p_to in varchar2,
    p_from in varchar2,
    p_subject in varchar2,
    p_text in varchar2 default null,
    p_html in varchar2 default null,
    p_smtp_hostname in varchar2,
    p_smtp_portnum in varchar2)
    is
    l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';
    l_connection utl_smtp.connection;
    l_body_html clob := empty_clob; --This LOB will be the email message
    l_offset number;
    l_ammount number;
    l_temp varchar2(32767) default null;
    begin
    l_connection := utl_smtp.open_connection( p_smtp_hostname, p_smtp_portnum );
    utl_smtp.helo( l_connection, p_smtp_hostname );
    utl_smtp.mail( l_connection, p_from );
    utl_smtp.rcpt( l_connection, p_to );
    l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);
    l_temp := l_temp || 'To: ' || p_to || chr(13) || chr(10);
    l_temp := l_temp || 'From: ' || p_from || chr(13) || chr(10);
    l_temp := l_temp || 'Subject: ' || p_subject || chr(13) || chr(10);
    l_temp := l_temp || 'Reply-To: ' || p_from || chr(13) || chr(10);
    l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' ||
    chr(34) || l_boundary || chr(34) || chr(13) ||
    chr(10);
    -- Write the headers
    dbms_lob.createtemporary( l_body_html, false, 10 );
    dbms_lob.write(l_body_html,length(l_temp),1,l_temp);
    -- Write the text boundary
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    l_temp := '--' || l_boundary || chr(13)||chr(10);
    l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' ||
    chr(13) || chr(10) || chr(13) || chr(10);
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Write the plain text portion of the email
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(p_text),l_offset,p_text);
    -- Write the HTML boundary
    l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||
    chr(13) || chr(10);
    l_temp := l_temp || 'content-type: text/html;' ||
    chr(13) || chr(10) || chr(13) || chr(10);
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Write the HTML portion of the message
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(p_html),l_offset,p_html);
    -- Write the final html boundary
    l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Send the email in 1900 byte chunks to UTL_SMTP
    l_offset := 1;
    l_ammount := 1900;
    utl_smtp.open_data(l_connection);
    while l_offset < dbms_lob.getlength(l_body_html) loop
    utl_smtp.write_data(l_connection,
    dbms_lob.substr(l_body_html,l_ammount,l_offset));
    l_offset := l_offset + l_ammount ;
    l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);
    end loop;
    utl_smtp.close_data(l_connection);
    utl_smtp.quit( l_connection );
    dbms_lob.freetemporary(l_body_html);
    end;

    There have been many very good threads on sending email using the UTL_SMTP on the forum including threads that deal with HTML formated mail.
    The basic process is to the same as with sending regular (non HTML) mail, but you add some additional headers to the mail message as well as additional formatting to the message body (e.g. HTML tags as needed).
    Specifically you need to add the two following headers:
    MIME-Version: 1.0
    Content-type: text/html

  • How to send HTML email in Mail?

    Hello All,
    I would like to write an email in HTML, just copy and paste the HTML code into mail, and have it sent as HTML. How do I have mail do this? Thanks!

    You can't do that; or rather, you can, but it won't work. You can view you r HTML file in Safari, then use the 'Mail Contents of This Page' option and Safari will insert the rendered HTML. But if your recipient doesn't have their mail program setup to view HTML email, they won't see whatever it is you're trying to accomplish.
    Mulder

Maybe you are looking for

  • Safari crashes everytime I try to open certain pages

    Hello, I'm having the same problem as Teresa in her post. I tried doing the steps mentinoned, nevertheless Safari still crashes at the same page everytime. I've got two (2) macs and the application crashes at the same place everytime i try to do some

  • How to use the time capsule with my existing router?

    Here is my situation. I have Alltel PCD UM185 USB modem for their mobile broadband internet. I have a Cradlepoint MBR1000 router which I plug the usb modem into to share the internet through a wireless network which has WPA security on it. I want to

  • Conversions in a planning View

    Hello everyone, In the SAP2 scenario there is a "conversion" tab available when designing a planning view (see picture). Could someone tell me how to make this Tab available? Thanks in advance

  • My iPad will not boot up or charge.

    Hello, I haven't used my iPad for a couple of months and wanted to turn it on. When I tried to, it wouldn't! I have plugged it in to the wall outlet for 30 minutes but still nothing. I tried plugging it into my computer but it will still not charge n

  • Complete newbie question - Can BI consume web services?

    Post Author: Steve Lamont CA Forum: Data Integration I am working on a new client site working on integration between a whole slew of systems including CRM, billing, BI etc.  The client is architecting a SOA oriented approach to all integration where