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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:22:23+00:00 2026-06-15T23:22:23+00:00

Hi I have to send email in java. The below has successfully worked for

  • 0

Hi I have to send email in java.

The below has successfully worked for me.

          public class SendMail {

             public static void main(String[] args) {                   
                 Properties props = new Properties();
                 props.put("mail.smtp.host", "smtp.gmail.com");
                 props.put("mail.smtp.socketFactory.port", "465");
                 props.put("mail.smtp.socketFactory.class",
                                "javax.net.ssl.SSLSocketFactory");
                 props.put("mail.smtp.auth", "true");
                 props.put("mail.smtp.port", "465");

                 Session session = Session.getDefaultInstance(props,
                                   new javax.mail.Authenticator() {
                                     protected PasswordAuthentication getPasswordAuthentication() {
                                        return new PasswordAuthentication("xxxx@gmail.com","xxxxx!1");
                                     }
                                   });

                  try {
                        Message message = new MimeMessage(session);
                        message.setFrom(new InternetAddress("krishnaveni.veeman@gmail.com"));
                        message.setRecipients(Message.RecipientType.TO,
                                      InternetAddress.parse("mercy.krishnaveni@gmail.com"));
                        message.setSubject("Testing Subject");
                        message.setText("Dear Mail Crawler," +
                                      "\n\n No spam to my email, please!");
                        Transport.send(message);
                        System.out.println("Done"); 
                      } catch (MessagingException e) {
                          throw new RuntimeException(e);
                      }
              }

           }

Here I have mentioned gmail username and password. But I have to send email without using username and password in my code. How can I develop this. Please help me.

  • 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-15T23:22:24+00:00Added an answer on June 15, 2026 at 11:22 pm

    create a mail.properties file and put username and password into in that file. Use Properties to retrieve data from this file in your code.

    This link could be useful to load Properties object

    http://www.dzone.com/snippets/loading-property-file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have send an email using php mailer class. mail was sending successfully but
I have java code for sending email with attachment as below. String myEmailId =
I have a constantly-running Java program that needs to send an email whenever it
I have a page called send.email.php which sends an email - pretty simple stuff
I have a page called send.email.php which sends an email - pretty simple stuff
I have written a perl script to send email using the gmail's smtp server:
I have to made a page which will send Email to Newsletter subscribers. There
I have a scenario where I am to send email using our own SMTP
I have following condition: How do I send email to example@mail.com on submitButton clicklistener
I have used default mail() function to send email it sends emails to yahoo

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.