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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:05:27+00:00 2026-06-10T17:05:27+00:00

I am using a program to send emails. The code works when I use

  • 0

I am using a program to send emails. The code works when I use some other mail server. but I need to use my company’s email account to send email. And the email account is provided by gmail xxxx@companyname.com. When I change the mail host to `stmp.gmail.com, I encounter the following error:

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command           first. st6sm11092256pbc.58

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
at javax.mail.Transport.send0(Transport.java:189)
at javax.mail.Transport.send(Transport.java:118)
at Mail.sendMail(Mail.java:48)
at Test.main(Test.java:6)

The code is as follows

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class Email_Autherticator extends Authenticator {
    String username = "xxxx@gmail";
    String password = "xxxxx";

    public Email_Autherticator() {
        super();
    }
    public Email_Autherticator(String user,String pwd){
        super();
        username = user;
        password = pwd;
    }

    public PasswordAuthentication getPasswordAuthentication(){
        return new PasswordAuthentication(username,password);
    }
} 


import java.util.Date;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mail {
    private String host = "smtp.gmail.com";
    private String mail_head_name = "this is head of this mail";
    private String mail_head_value = "this is head of this mail";
    private String mail_to = "xxxx@gmail.com";
    private String mail_from = "xxxx@Comanyname.com";//using gmail server
    private String mail_subject = "this is the subject of this test mail";
    private String mail_body = "this is mail_body of this test mail";
    private String personalName = "xxx";

    public void sendMail() throws SendFailedException{
        try {
            Properties props = new Properties();
            Authenticator auth = new Email_Autherticator();
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.auth", "true");
            System.out.println(props);
            Session session = Session.getDefaultInstance(props,auth);

            MimeMessage message = new MimeMessage(session);
            message.setContent("Hello","text/plain");
            message.setSubject(mail_subject);
            message.setText(mail_body);
            message.setHeader(mail_head_name, mail_head_value);
            message.setSentDate(new Date());
            Address address = new InternetAddress(mail_from,personalName);
            message.setFrom(address);
            Address toaddress = new InternetAddress(mail_to);
            message.addRecipient(Message.RecipientType.TO,toaddress);
            System.out.println(message);
            Transport.send(message);
            System.out.println("Send Mail Ok!");
        } catch (Exception e) {
            e.printStackTrace();
        }
        //return flag;
    }
}
  • 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-10T17:05:29+00:00Added an answer on June 10, 2026 at 5:05 pm

    You almost certainly just need to rework your code to add the properties defined in the JavaMail API – Sending email via Gmail SMTP example example.

    You can probably get away with setting your props to this:

    Properties properties = new Properties();
    
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.starttls.enable", "true");
    properties.setProperty("mail.smtp.host", "smtp.gmail.com");
    properties.setProperty("mail.smtp.port", "587");
    properties.setProperty("mail.smtp.user", gmailUsername);
    properties.setProperty("mail.smtp.password", gmailPassword);
    

    As this seems to be for work–if you can–I suggest using Spring. It makes it a lot cleaner and easier to use. I just recently did something similar to this with Spring and Gmail SMTP.

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

Sidebar

Related Questions

I am trying to use Java Mail to send emails with my program but
I am developing some program in C# which will send the mail using outlook
I want to send email to Yahoo mail using Indy. But Yahoo uses 465
I need a program that will be used to send email using SMTP from
I want that my program could send email without using Microsoft Outlook or other
I have a program to send POST request to a server. I'm using cURL
I am trying to send mail using SmtpClient() within my Winforms VB.Net program Here
I want to send an email with an attachment using the following code (Python
I'm using the code from this link to send attachments in the email notifications
I'm working with a program that can send email supporting yahoo mail and gmail.

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.