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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:45:42+00:00 2026-06-06T18:45:42+00:00

Below is the code I have for sending email which works great. /* *

  • 0

Below is the code I have for sending email which works great.

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package myWorkingFiles;

import org.apache.commons.mail.*;

/*
*
* @author xyz
*/
public class GmailEmailWorking {

    public static void main(String[] args) {
        String myEmailId = "myEmailId@gmail.com";
        String myPassword = "myPassword";
        String senderId = "senderId@yahoo.co.in";
        try {
            Email email = new SimpleEmail();
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword));
            email.setDebug(true);
            email.setHostName("smtp.gmail.com");
            email.setFrom(myEmailId);
            email.setSubject("Hi");
            email.setMsg("This is a test mail ... :-)");
            email.addTo(senderId);
            email.setTLS(true);
            email.send();
            System.out.println("Mail sent!");
        } catch (Exception e) {
            System.out.println("Exception :: " + e);
        }
    }
}

Now I want to send email with attachement as oppose to plain email as shown above.

Please let me know what changes I will need to do? I believe its easy, but sadly Mr. Google is also not helping me.

I have found some links but they are not useful.

http://www.tutorialspoint.com/jsp/jsp_sending_email.htm

  • 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-06T18:45:44+00:00Added an answer on June 6, 2026 at 6:45 pm

    A quick search landed me with this ..
    http://commons.apache.org/email/userguide.html

    Are u trying to search for something different??

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

Sidebar

Related Questions

I have a problem sending POST request with VB6. The code below works properly
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have the code below which I am using to upload files to my
I am sending email throught SMTP Client using below code. MailMessage objMail = new
In my app, I have email sending code. It's quite plain-vanilla (pasted at end
I have a question about using form_dropdown() . The code below works, but i
I have the following code, which sends emails but it is embedding one email
In the code below I have a StreamReader reading from a network stream. This
3 I am getting error in sending mail.here below i have mentioned my code.
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server

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.