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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:51:43+00:00 2026-06-09T07:51:43+00:00

Trying to get Play! Framework to send an email with an attachment. Code below

  • 0

Trying to get Play! Framework to send an email with an attachment. Code below works fine if I don’t add the attachment to the message. I’ve tried both with Play’s Mailer class and with the Apache Commons classes (as below), but in both cases, the page just sits there with a spinner (Chrome) and no email is received.

EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL(base + "public/images/triangles.png"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("test");
attachment.setName("test");

emailaddress = "test@test.com";

MultiPartEmail email = new MultiPartEmail();
email.setDebug(true);
email.addTo(emailaddress);
email.setFrom("Testing <test@test.com>");
email.setSubject("Testing email");
try
{
    email.attach(attachment);
}
catch (EmailException ex)
{
    System.out.println(ex.getMessage());
}
email.setMsg("test email");
email.send();
  • 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-09T07:51:44+00:00Added an answer on June 9, 2026 at 7:51 am

    Im guessing you’ve already had a look at the Examples for Apache Commons and Sending e-mail – Play! Framework 1.1?

    IMO I’d suggest using a well known library with loads of documentation and examples like JavaMail and their api.

    Here are a few tutorials that will get you started immediately:

    • JavaMail quick start
    • Java Mail SMTPClient Example
    • Sending mail with attachment with javamail

    An example of using the JavaMail to send a Email with attachment via gmail is:

    import java.util.Properties;
    
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.PasswordAuthentication;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    
    public class SendMailTLS {
    
    public static void main(String[] args) {
    
        final String username = "username@gmail.com";
        final String password = "password";
    
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");
    
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
    
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });
    
        try {
    
            // Define message
            MimeMessage message =
                    new MimeMessage(session);
            message.setFrom(
                    new InternetAddress(from));
            message.addRecipient(
                    Message.RecipientType.TO,
                    new InternetAddress(to));
            message.setSubject(
                    "Hello JavaMail Attachment");
    
            // create the message part 
            MimeBodyPart messageBodyPart =
                    new MimeBodyPart();
    
            //fill message
            messageBodyPart.setText("Hi");
    
            Multipart multipart = new MimeMultipart();
            multipart.addBodyPart(messageBodyPart);
    
            // Part two is attachment
            messageBodyPart = new MimeBodyPart();
            DataSource source =
                    new FileDataSource(fileAttachment);
            messageBodyPart.setDataHandler(
                    new DataHandler(source));
            messageBodyPart.setFileName(fileAttachment);
            multipart.addBodyPart(messageBodyPart);
    
            // Put parts in message
            message.setContent(multipart);
    
            // Send the message
            Transport.send(message);
    
    
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    }

    HTH

    References:

    • JavaMail API – Sending Email Via Gmail SMTP Example
    • http://www.jguru.com/faq/view.jsp?EID=30251
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to play video from youtube using this code but I get this
I have the following code i am trying to get the play speed rank
I am trying to perform some custom validation with play framework but I don't
I'm trying to get started with the play web framework and its scala support,
I'm trying to port some code from Play Framework Java to Play Framework Scala
I'm trying to use JMF (Java Media Framework) to play a video. I've tried
Trying to get an animation to play backwards while a button is held down,
I am just starting to play with nservice bus and am trying to get
I'm working with PyQt and trying to get video from a webcam to play
So, I'm trying to get a video to play from an HTTP url. To

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.