Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:39:49+00:00 2026-05-28T01:39:49+00:00

I am using JavaMail API 1.4.4 to send mails. So far I am able

  • 0

I am using JavaMail API 1.4.4 to send mails. So far I am able to send the mail, but actually I need to send HTML content so that when the mail is received it processes the html tags.

Example: if I have a table code in my message it should process the html code and present it in the mail

My Code

import java.io.File;
import java.util.*
import javax.mail.*
import javax.mail.internet.*
import javax.activation.*

class Mail {
  static void sendMail(mailProp) {      
    // Get system properties
    Properties properties = System.getProperties()

    // Setup mail server
    properties.setProperty("mail.smtp.host", mailProp.host)

    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties)

    try {
      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(session)

      // Set From: header field of the header.
      message.setFrom(new InternetAddress(mailProp.from))

      // Set To: header field of the header.
      message.addRecipient(Message.RecipientType.TO,new InternetAddress(mailProp.to))

      // Set Subject: header field
      message.setSubject("My Subject!")

      // Now set the actual message
      message.setText(createMessage())

      // Send message
      Transport.send(message)
      System.out.println("Sent message successfully....")
    }
    catch( MessagingException mex ) {
        mex.printStackTrace()
    }
  }

  static def createMessage() {
    def message="""<h1>This is actual message</h1>"""
  }

  static main(args) {
    AppProperties.load()

    def mailProp=[:]
    mailProp.host=AppProperties.get("host")
    mailProp.from=AppProperties.get("sender")
    mailProp.to=AppProperties.get("receiver")
    mailProp.server=AppProperties.get("mailserver")

    sendMail(mailProp)
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:39:49+00:00Added an answer on May 28, 2026 at 1:39 am

    A Groovier way of sending might be:

    try {
      // Create a default MimeMessage object.
      new MimeMessage(session).with { message ->
        // From, Subject and Content
        from = new InternetAddress( mailProp.from )
        subject = "My Subject!"
        setContent createMessage(), 'text/html'
    
        // Add recipients
        addRecipient( Message.RecipientType.TO, new InternetAddress( mailProp.to ) )
    
        // Send the message
        Transport.send( message )
    
        println "Sent successfully"
      }
    }
    catch( MessagingException mex ) {
        mex.printStackTrace()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I need to make an imap client (using java mail api) that if,
I am receiving error when I try to send a mail using JavaMail API
I am using Javamail (javax.mail) to send mails. I successfully adjusted contents of my
I'm using the JavaMail API that's been ported for Android found here but I
Using JavaMail, I am able to read and download mails from Gmail, but it
I'm trying to send an email using JavaMail API. I have jdk 1.5 installed
I am sending email using Java Mail API. When the email is received in
I am trying to send mail using java mail api. My smtp server is
I have this servlet which needs to send mail using Java Mail API, however
I'm trying to send a message by using Javamail API, with tomcat as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.