Java.mail sending email in html format

I trying to send emails from my java program, I ve managd to send text mails, I want to send email in html format is there a way of doing that and how
thanks for your help

Thanks a lot it is working now but I think that sending mails in text format is the best way since there isn't a way of knowing whether the recepient can handel html mails

Similar Messages

  • Send Email in HTML Format with Javamail.

    GOD BE BLESSED!
    Hello dudes,
    i create a jsp page let me send emails from a database using the API Javamail.
    But these emails when i send then, goes in text format only, and i want to send emails in HTML format too. Anyone can help me?
    I think the Javamail API can send in HTML format.
    thanks and sorry, my english is basic but i think you understand. ;)
    Adler Medrado

    I was trying to do the same thing...I found this on the java.sun.com website somewhere. Hope it works out for you.
    try {
    String host = "";
    String from = "";
    String to = "";
    String fileAttachment = fileName;
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session1 =
    Session.getInstance(props, null);
    // Define message
    MimeMessage message =
    new MimeMessage(session1);
    message.setFrom(
    new InternetAddress(from));
    message.addRecipient(
    Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject("");
    // create the message part
    MimeBodyPart messageBodyPart =
    new MimeBodyPart();
    //fill message
    messageBodyPart.setText("");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source =
    new FileDataSource(fileAttachment);
    messageBodyPart.setDataHandler(
    new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send( message );
    }catch (Exception e){
    System.err.print("Mailing error:");
    System.err.println(e);

  • Send Email with HTML format in Outlook Macro

    I can use the following to send email with HTML format in VBA. I also have created an HTML file. Is there a way to load the file into .HTMLBody to send it as HTML format message?
        Set OutlookApp = CreateObject("Outlook.Application")
        Set objMail = OutlookApp.CreateItem(olMailItem)
        With objMail
           .BodyFormat = olFormatHTML
           .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"
           .Display
        End With

    Try: 
    Dim fso As Scripting.FileSystemObject
    Dim htmlFile As Scripting.TextStream
    Set fso = New Scripting.FileSystemObject
    Set htmlFile = fso.OpenTextFile("C:\path\to\my-html-file.htm")
    strInsert = htmlFile.ReadAll
    then change:
    .htmlbody = strInsert
    oh, and you need to set a reference to the Scripting runtime in Tools, References. 
    Diane Poremsky [MVP - Outlook]
    Outlook & Exchange Solutions Center
    Outlook Tips
    Subscribe to Exchange Messaging Outlook weekly newsletter

  • Sending email in html format.

    i am trying to send email in html format. the following is my sample code. it's just sending plain text. how should i send html file in email?
    String message_body = "<a href=\"test.html\">click here</a>";
    MimeMessage msg = new MimeMessage( session );
    // From Address
    msg.setFrom( new InternetAddress( fromAddress ) );
    // TO Address
    InternetAddress recipient_Address = new InternetAddress( toAddress );
    msg.addRecipient(Message.RecipientType.TO, recipient_Address);
    // Subject
    msg.setSubject( subject );
    // MimeBodyPart object for message body part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText( message_body );
    // MimeBodyPart object for file to attach
    MimeBodyPart mbp2 = new MimeBodyPart();
    Multipart mp = new MimeMultipart();
    // create the Multipart and add message body and file to attach.
    mp.addBodyPart(mbp1);
    // add the Multipart to the message
    msg.setContent(mp);
    msg.setSentDate(new Date());
    // send the message
    Transport.send(msg);
    i'd appreciated it...

    msg.setContent(mp, "text/html");Have I put this in the right place? You need to apply it to your body text, at any rate.

  • Send email in html format

    Hello everybody,
    First of all:
    I already searched via internet but couldn´t found an example which helped me to solve my problem. Anyway I believe it must be very simple what I want to do.
    My Problem: I want to send an email in html format, but until now everything I tried didn´t worked. Please help me. What do I have to do?
    I already tried a lot of code typing. For example this one:
    this.resolveNode("#event").submit.target="mailto:"+email_adressen+"subject="+subject+"&Body="+body+"&MessageFormat=HTML";
    But nothing is working, you always see the html tags in the text - they have no effect at all :-( .
    Best regards,
    Paolo

    I was trying to do the same thing...I found this on the java.sun.com website somewhere. Hope it works out for you.
    try {
    String host = "";
    String from = "";
    String to = "";
    String fileAttachment = fileName;
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session1 =
    Session.getInstance(props, null);
    // Define message
    MimeMessage message =
    new MimeMessage(session1);
    message.setFrom(
    new InternetAddress(from));
    message.addRecipient(
    Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject("");
    // create the message part
    MimeBodyPart messageBodyPart =
    new MimeBodyPart();
    //fill message
    messageBodyPart.setText("");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source =
    new FileDataSource(fileAttachment);
    messageBodyPart.setDataHandler(
    new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send( message );
    }catch (Exception e){
    System.err.print("Mailing error:");
    System.err.println(e);

  • Send emails in html format

    Hi All,
    My requirement is to send emails. I am using javamail and it works fine. But the body of the email should be in table format.
    I am planning to use Html as below. But don't know how to combine html in java. Is there any other way of achieving it ? Please let me know if I am not clear.
    <htm>
    <table border="1">
    <tr>
    <td bgcolor="red">Header</td>
    </tr>
    <tr>
    <td bgcolor="yellow">Sub Header1</td>
    <td bgcolor="yellow">Sub Header1</td>
    </tr>
    <tr>
    <td bgcolor="green">Values</td>
    <td bgcolor="green">Values</td>
    </tr>
    </html>

    so, do I need another method which tells Java whereto output the HTML Tags ?
    The method writes to a PrintWriter defined somewhere,
    you can also pass the PrintWriter as third argument
    to the method.
    To generate a String containg the whole HTML Dokument
    you would write something like:
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new
    PrintWriter(stringWriter);
    writeStartTable();
    writeStartRow();
    writeCell("BlaBla", "green");
    printEndTable();
    printWriter.flush();
    printWriter.close();
    stringWriter.close();
    String content = stringWriter().toString();
    BodyPart mailBody = new MimeBodyPart();
    mailBody.setContent(content, "text/html");
    I was succesful in sending mail using HTML format. Thanks for ur reply.
    But if I try send the mail in HTML format along with an attachment, the MIME type defaults to "text/plain".
    Is there a way to set the MIME type to "text/html" when I send mail with an attachment.
    Please help . Let me know if I am not clear

  • Send email in html format with pdf attachment

    I am trying to send an email out of SAP using an abap program in the html format with a pdf attachment. I am using the function module -SO_DOCUMENT_SEND_API1. I noticed that when i specify the body type of the message as 'RAW' I get to see the pdf attachments however when i switch it to 'HTM' I loose the attachment in the email generated. Can anyone please help me in solving this problem. Thanks!

      ld_email                 = p_email. "All email IDs
      ld_mtitle                 = 'Bank Statement'.
      ld_format                = 'PDF'. "Attachment Format
      ld_attdescription      = 'Statement'.
      ld_attfilename          = p_filename. "Name of file
      ld_sender_address      = p_sender_address. "Sender mail address
      ld_sender_address_type = p_sender_addres_type. "INT - Internet
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle . "Description
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle. "Description
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'HTM'. " THis is for BODY of mail RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      ld_error = sy-subrc.

  • Send email in HTML format with attachment.

    I want to send out email in HTML fromat and attach a file to it. I know how to send HTML email but I cant attach a file to it.
    Can anybody help me with that?

    What kind of attachment?
    1) A file not related to the HTML
    or 2) a file used by the HTML (i.e. a GIF)?
    If 1) see here http://developer.java.sun.com/developer/onlineTraining/JavaMail/contents.html#SendingAttachments
    If 2) see here http://forum.java.sun.com/thread.jsp?forum=43&thread=242791
    (make sure you read all the thread as inline attachments are mentioned at the end)
    SH

  • Sending an email in HTML format

    in order to change the mail format from PDF to HTML format, first I create  the smartform with the relevant content , secont I create a new class and implement the method with the code mentioned in the blog "sending HTML Email from SAP CRM/ERP"  and I defined at the action profile in IMG (I didn't
    add nothing but the method mentionedin the blog).
    the appointment is saved and the mail is sent in HTML format . but an error message is send to the user at the crm_ic tranzaction. the error message is BS(001) " no status object is available for &".
    the message is raised from program LCRMBSVAF14 / form status_read.
    if I put break-point at the message line(86)  , the message is shown and the crm_ic tranzaction is stoped
    but if I put break-point a few lines before(line no 33)  and track each step the tranzaction function correct and the crm_ic show  an o.k. message  , I can not find a reason why the tranzaction process with break-point and don't pass with out it.
    thank you .

    rj_oregon wrote:
    If you like email me out-of-band and I can send you a full sample .txt file of "hello world" that takes 3K in plain text, 256KByte in rich-text, most of it injected.
    If it looks anything like the sample here, that's unnecessary:
                             Test_Email_Adblock_enabled.txt          
    If what you see is substantially different, though, I'd be interested in seeing it. (I can't e-mail you, though, as I don't know your e-mail address. You can find mine, though, by looking at the contact link at the bottom of any page on my site, listed in my profile here.)
    This is not a feature in adblock, I view it as a bug.
    I agree, it should not be doing that.
    My suspicion is that AdBlock works by adding this code to every page you view, thus rendering the advertising elements invisible. However, in the case of OWA, it must be inserting that code in a bad place, where it shows up in the message. Mail servers will be prone to rejecting such a message, probably because some of the strings that code uses to identify these ads might look malicious. There's nothing that I can see in that code that's actually malicious, though... just a bunch of CSS conditions that make matching elements invisible.

  • How to view my email in HTML format instead of Plain Text format?

    I receive plenty of HTML format emails everyday.
    but when I check those emails on iPhone, all emails were automatically converted to Plain Text format.
    I wish to view my emails in HTML format (just as it shown in Outlook)
    with graphic (jpep loaded, instead of attachment), and Text formatting.
    Can anyone suggest me any solution?
    or do Mail apps in iPhone does not support HTML format?
    Pls guide.
    Thx.

    To get a source code for jsp mail visit http://www.jspinsider.com/tutorials/jsp/javamail.view

  • Send report in HTML format not in MHTML

    Hi all,
    I need to send report in email in HTML format not in MHTML format.
    Kindly help me.
    Thanks

    Hello,
    As far as I know, we cannot change the rsreportserver.config file to achieve this effect.
    In SSRS, the HTML rendering extension renders a report in HTML format. The HTML rendering extension is the default rendering extension for reports that are previewed in Report Builder and viewed in a browser, including when run in Report Manager.
    There is an article about Rendering to HTML, you can refer to it.
    http://technet.microsoft.com/en-us/library/dd255269.aspx
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • Sending emails in HTML on iPhone?

    How do I configure the iPhone 5 to send emails in HTML? 

    Lucky I stopped by again
    We have heard of this problem from a small number of people over the last few weeks.
    Briefly it seems that some contacts can be formatted weirdly in your address book. The easiest solution seems to be to export the problem contact as vcf and reimport, which cleans the contact in some way, then it should be fine.
    More on solubleapps.com/MailShot-support, if you haven't visited there already.
    Any problems please get in touch on our support email address and we'll try our best to help. Also Watch for the new update in a week or so.
    Cheer, Peter

  • Mail send email at 2 kbs

    Hi I use mail to send email from 3 different accounts and my mail sends email a 2kbs sometime 4Kbs
    I send a lot of quicktime to my clients and it takes forever to send a 3MB files.
    HELP !

    Plus eMail will make that 3MB file into 4.5-6MB in sending.
    What do you get for raw speeds up & down here, for both Java & Flash, DSL Reports...
    http://www.dslreports.com/stest

  • Customization of DAC to send emails in XML format

    Hi,
    We need to customize DAC to send emails in XML format to the support team whenever there is a failure of the ETL load.
    We use the HPSC ticketing system.
    Any help to achieve this functionality is much appreciated.
    we have tried to customize the existing email template of DAC, but it is not serving the purpose to generate the ticket in HPSC.
    To generate the HPSC ticket, we have a XML format. We need to customize DAC to use this format.
    This is the version of Oracle BI application we are using:
    Build: 10.1.3.2.1.070411.1900
    Release Version: Oracle Business Intelligence 10.1.3.2.1
    Package: 070411.1900
    Build: 7.9.1.032307.0900
    Release Version: Oracle Business Intelligence Applications 7.9.1
    Package: 032307.0900
    Regards,

    Hi,
    We have raised a SR with Oracle support and are in touch with Engineering also today onwards. However, would like to try out options while waiting for a solution/workaround for this issue.
    Regards,

  • Blank email with HTML format

    when I get an email in HTML format on my phone , the message comes in whiteand occasionally get the html code unencrypted. i use Iphone 6 and my email server its Exchange server 2010 on premise.
    I hope you can help me.

    Try: 
    Dim fso As Scripting.FileSystemObject
    Dim htmlFile As Scripting.TextStream
    Set fso = New Scripting.FileSystemObject
    Set htmlFile = fso.OpenTextFile("C:\path\to\my-html-file.htm")
    strInsert = htmlFile.ReadAll
    then change:
    .htmlbody = strInsert
    oh, and you need to set a reference to the Scripting runtime in Tools, References. 
    Diane Poremsky [MVP - Outlook]
    Outlook & Exchange Solutions Center
    Outlook Tips
    Subscribe to Exchange Messaging Outlook weekly newsletter

Maybe you are looking for

  • Play back problem!!

    hi, i was juz wondering, when i play a song and i put it on repeat it kinda lag during the transition of the repeat. in another word when it about to end and start the song all over again, at that moment it will lag mi computer, making the computer p

  • Is this case program a scam!?

    I purchased a new iPhone 4 on Aug 24 from an AT&T store and that evening downloaded the app to order my free case. I got an error that said my phone isn't eligible. According to the Terms and Conditions my phone IS eligible!!! Well, after being on th

  • Business Area : Diff between Division & Item Division

    Hi, In SAP we can determine business area with 3 diff rules. Oner is through sales area (Sales. OrgDist channel Division) second one is by plant and item division.and the last one is through Sales orgdist ChannelItem division. Can any one tell me wha

  • Reset samba passwords - Mission impossible?

    hi! Yesterday night I tried to set a password for a new user (of a Windows XP) so that I may connect my MacBook to a PC. Reason: I never managed to connect the both of them. I was always receiving a kind of "wromng user/password message (do not remem

  • Parent Instance creating many child instances in SOA-INFRA

    Hi, We have deleted a parent instance from SOA-INFRA database.Even after deletion it keeps on creating child instances. How to identify all the child instances of the parent instance in SOA-INFRA schema . Also, we searched a lot but were unable to ge