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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:13:18+00:00 2026-06-05T20:13:18+00:00

This is a sample function to send an email using Gmail public void sendEmail(String

  • 0

This is a sample function to send an email using Gmail

    public void sendEmail(String from, ArrayList<String> to, String subject,
        String content, boolean contentIsHtml) throws EmailException 
{
    try
    {
        Properties props = new Properties();

        props.put("mail.transport.protocol", EmailConfig.getGmailTransportProtocol());
        props.put("mail.smtp.host", EmailConfig.getGmailSMTPHost());
        props.put("mail.smtp.socketFactory.port", EmailConfig.getGmailSMTPPort());
        props.put("mail.smtp.socketFactory.class", EmailConfig.getSocketFactoryClass());
        props.put("mail.smtp.auth", EmailConfig.getGmailAuthRequired());
        props.put("mail.smtp.port", EmailConfig.getGmailSMTPPort());


        SMTPAuthenticator authenticator = new SMTPAuthenticator();

        Session session = Session.getDefaultInstance(props, authenticator);
        //session.setDebug(true);

        Transport transport = session.getTransport();

        MimeMessage message = new MimeMessage(session);
        message.setSubject(subject);
                    message.setSender(EmailUtil.getInternetAddress(
                    EmailConfig.getGmailUsername(), "jatin Shah"));
        message.setRecipients(
                        RecipientType.TO,  
                       EmailUtil.getInternetAddresses(to));
        if(contentIsHtml)
            message.setContent(content, "text/html");
        else
            message.setContent(content, "text/plain");

        transport.connect();
        transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
        transport.close();

        System.out.println("Email Sent!!");

    }
    catch(Exception e)
    {
        e.printStackTrace();
        throw new EmailException(e);
    }
}

This sends an email using MyGmail account

I am sending an email from gmail account to another in my test

However, when I receive an email it is fine … however, the full name of the sender is now shown

Instead of “Jatin Shah” (my name) … it shows bhatin.shah (My Username)

  • 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-05T20:13:20+00:00Added an answer on June 5, 2026 at 8:13 pm

    First, read this FAQ entry of common mistakes.

    To fix your problem, use setFrom instead of setSender.

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

Sidebar

Related Questions

I want to send Email through C/C++ program using my Gmail Account. I find
I'm trying to send an e-mail with Codeigniter like this: $this->load->library('email'); $this->email->from(myemail@email.com); $this->email->reply_to(myemail@email.com); $this->email->to(myemail@email.com);
This is sample of function in the Staff controller for this question function newStaff()
This is a sample pgm to check the functionality of Sleep() function.This is a
I'm using this simple function: def print_players(players): tot = 1 for p in players:
I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
I'm attempting to write a Python function to send an email to a list
I am new to PHP and I'm using the mail function to send emails
I am trying to send some files from a folder to a fixed email
I've wrote a simple function to check if the string I send should be

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.