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 8308267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:45:19+00:00 2026-06-08T18:45:19+00:00

I am using the following code to send mail: protected void mailSettings() { Object

  • 0

I am using the following code to send mail:

protected void mailSettings() {
    Object lookedUp = null;
    String mailSettingValues[] = null;
    try {
        InitialContext initialContext = new InitialContext();
        lookedUp = initialContext.lookup("java:/comp/env/mailsettings");
        mailSettingValues = lookedUp.toString().split(",");
        smtphost = mailSettingValues[0];
        port = mailSettingValues[1];
        username = mailSettingValues[2];
        password = mailSettingValues[3];
    } catch (NamingException e) {
        e.printStackTrace();
    }

    m_properties = new Properties();
    m_properties.put("mail.smtp.host", smtphost);
    m_properties.put("mail.smtp.auth", "true");
    m_properties.put("mail.smtp.starttls.enable", "true");
    m_properties.put("mail.smtp.port", port);

    m_Session = Session.getDefaultInstance(m_properties,
            new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

}

public void sendMail(String mail_from, String mail_to, String mail_subject,
        String m_body) {
    try {
        m_simpleMessage = new MimeMessage(m_Session);
        m_fromAddress = new InternetAddress(mail_from);
        m_toAddress = new InternetAddress(mail_to);

        m_simpleMessage.setFrom(m_fromAddress);
        m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
        m_simpleMessage.setSubject(mail_subject);

        m_simpleMessage.setContent(m_body, "text/plain");

        Transport.send(m_simpleMessage);
    } catch (MessagingException ex) {
        ex.printStackTrace();
    }
}

As of this code we need to have email from address and the password for the same, but I would like to send mail to to_email address without the authentication(getting user password).

How can this be done?

I need to do the following things:

  1. get the from address from properties or context file
  2. get the to address from properties or context file
  3. send mail to to_address without authenticating the from address
  • 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-06-08T18:45:21+00:00Added an answer on June 8, 2026 at 6:45 pm
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    
    public class SimpleSendEmail {
        public static void main(String[] args) {
    
            String host = "your smtp host";
            String to = "bbbb@ddddd.com";
            String from = "xxxx@yyy.com";
            String subject = "My First Email";
            String messageText = "I am sending a message using the"
                    + " JavaMail API.\n" + "Here type your message.";
            boolean sessionDebug = false;
            Properties props = System.getProperties();
            props.put("mail.host", host);
            props.put("mail.transport.protocol", "smtp");
            Session session = Session.getDefaultInstance(props, null);
            // Set debug on the Session so we can see what is going on
            // Passing false will not echo debug info, and passing true
            // will.
            session.setDebug(sessionDebug);
            try {
                Message msg = new MimeMessage(session);
                msg.setFrom(new InternetAddress(from));
                InternetAddress[] address = { new InternetAddress(to) };
                msg.setRecipients(Message.RecipientType.TO, address);
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setText(messageText);
    
                Transport.send(msg);
            } 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

I have to written the following code to send a mail using PHP in
I am trying to send email using c# following is my code. try {
I'm using the following piece of code in Android to send a mail: Intent
I'm using Zend_Mail and the following code to send my email messages. $mail =
I'm trying to send mail from my application server using the following code FILE
I'm trying to send a mail using Zend_Mail using the following code: function sendMail()
i am using following code, to send a mail, with two attachments, Problems i'm
I'm using following code to send sms throuh gsm modem for (int i =
i am using the following code to send out error message to client from
i am using the following code to send a request in jsonp using google

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.