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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:31:38+00:00 2026-06-05T15:31:38+00:00

I am using the JavaMail port for android to send emails without user intervention

  • 0

I am using the JavaMail port for android to send emails without user intervention in the application. And I have noticed that some email systems does not display the email body correctly. When I send the email to Gmail the body is shown correctly, but when I send it to a company email (I am not exactly sure what it is using but it’s a business mail from Telecom) the body is blank and instead there is an attachment of a text file ATT00001.txt with the content of body.

I am not an expert on the mail systems but from the code I use to set the body of email it seems like it is very similar to how you attach a file, and maybe that is why the body is not recognised as the body, but as an attachment.

The following code snippet is how the mail is created. The body and subjects are all initialised beforehand.

public synchronized void send() throws MessagingException {   
    MimeMessage message = new MimeMessage(session);   
    BodyPart bodyPart = new MimeBodyPart();
    bodyPart.setText(body);
    message.setSender(new InternetAddress(sender));   
    message.setSubject(subject);   
    //message.setDataHandler(handler);
    multipart.addBodyPart(bodyPart);
    message.setContent(multipart);
    if (recipients.indexOf(',') > 0)   
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
    else  
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));   
    Transport.send(message);  
    user = null;
    password = null;
    session = null;
}   

If anyone knows how to get around this problem please help me! It is important for my application to show the body as the body. Also, if there is a better way of sending emails without user intervention, please suggest them too.

Thanks for your help.

EDIT:

I tried using .setText() instead of BodyPart

message.setText(body);

This did not show the body at all from Gmail, and showed some weird string from the company mail

——=_Part_2_1079750440.1339556360521–

And while testing these, I created an email test activity which basically sends an email with a button click. After trying out a few things, I changed my class back to how it was (using BodyPart) and then it worked! It looks like the attachment was causing the problem and I think the way I’m attaching my files isn’t correct.

public void addAttachment(File file) throws MessagingException {
    BodyPart messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(file);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(file.getName());
    multipart.addBodyPart(messageBodyPart);     
}

This addAttachment() function is called before send().

What is wrong with this?

EDIT:

In case anyone else is having the same issues, here’s how I fixed it. The problem was fixed by setting the body before adding attachments. So instead of setting the body when sending, I set the body separately beforehand.

public void setBody(String body) throws MessagingException {
    BodyPart bodyPart = new MimeBodyPart();
    bodyPart.setText(body);
    multipart.addBodyPart(bodyPart);
}

public synchronized void send() throws MessagingException {   
    MimeMessage message = new MimeMessage(session);   
    message.setSender(new InternetAddress(sender));   
    message.setSubject(subject);   
    message.setContent(multipart);
    if (recipients.indexOf(',') > 0)   
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
    else  
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));   
    Transport.send(message);  
    user = null;
    password = null;
    session = null;
}   

So when I call the functions, I call setBody() first, then addAttachment(), then send().
Now the body of the email is shown as it should.

  • 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-05T15:31:39+00:00Added an answer on June 5, 2026 at 3:31 pm

    Try just creating a plain text message without using a multipart. Get rid of message.setContent(multipart) and use message.setText(body).

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

Sidebar

Related Questions

Sending Email in Android using JavaMail API without using the default/built-in app I'm trying
Possible Duplicate: Sending Email in Android using JavaMail API without using the default android
I'm trying to send an email using JavaMail API. I have jdk 1.5 installed
My application needs to send emails on an ad hoc basis. I'm using javamail's
Following this thread : Sending Email in Android using JavaMail API without using the
I followed this thread to connect to gmail to send email without user intervention:
I'm following this example: Sending Email in Android using JavaMail API without using the
Possible Duplicate: Sending Email in Android using JavaMail API without using the default Android
Having to interact with several different email servers via IMAP (using javamail), I have
I'm using the JavaMail API that's been ported for Android found here but I

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.