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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:51:24+00:00 2026-06-11T19:51:24+00:00

I have an application that sends emails. But in my development environment, I don’t

  • 0

I have an application that sends emails. But in my development environment, I don’t want the application to send email, rather it should only print the message in log file.

There are a fake javax.mail.Session implementation that I can do this?

  • 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-11T19:51:25+00:00Added an answer on June 11, 2026 at 7:51 pm

    For this problem I would use a custom javax.mail.Transport which is registered to the SMTP protocol.

    First implement the CustomTransport class

    import javax.mail.Transport;
    import javax.mail.*;
    
    public class CustomTransport extends Transport {
    
      public CustomTransport(Session smtpSession, URLName urlName) {
        super(smtpSession, urlName);
      }
    
      @Override
      public void sendMessage(Message message, Address[] addresses) throws MessagingException {
        // Take the message and write it somewhere
        // e.g.: a logger or an OutputStream message.writeTo(...);
      }
    
      @Override
      public void connect() throws MessagingException {}
    
      @Override
      public void connect(String host, int port, String username, String password) throws MessagingException {}
    
      @Override
      public void connect(String host, String username, String password) throws MessagingException {}
    
      @Override
      public void close() {}
    }
    

    Afterwards you can use that CustomTransport to create a javax.mail.Session which writes your mails to the defined location

    public Session getMailSession(){
      Properties props = new Properties();
      props.put("mail.transport.protocol", "smtp");
      props.put("mail.smtp.provider.class", CustomTransport.class.getName());
      props.put("mail.smtp.provider.vendor", "foo");
      props.put("mail.smtp.provider.version", "0.0.0");
    
      return Session.getInstance(props);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that sends verification emails to people account email address, but
I want to write an application that sends html formatted email. I have the
I have a PHP application that sends email using the pear Mail function. Unfortunately
I have an application that sends an HTML formatted email with embedded images. The
i have an application that uses SMTP to send emails from an yahoo account.
I have a Play Framework application that sends emails using SMTP server. Now I
I have a small WinForms application that sends notification emails. It works fine with
This is probably a stupid question, but... I've got an application that sends emails
A have ASP.NET 2.0 web application that should allow sending emails. I have a
I have an application that reads emails from ONE email account (gmail application account)

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.