How to send attachment + message body inside one EmailSending Email in Android using JavaMail API without using the default/built-in appHow to send an object from one Android Activity to another using Intents?How can I send emails from my Android application?How to attach pdf file from assets in email?Send Email IntentHow to nest MimeBodyParts in JavaMail (standard email messages)?Setting Content-Type for MimeMessage?Body message does not appear when sending attachmentsJavaMail content-transfer-encoding issueAndroid JavaMail cancel sending email
Find all files in directories named foo
What to do as a player when ranger animal companion dies
How could artificial intelligence harm us?
Do liquid propellant rocket engines experience thrust oscillation?
Is it safe to unplug a blinking USB drive after 'safely' ejecting it?
Delete empty subfolders, keep parent folder
I was cheated into a job and want to leave ASAP, what do I tell my interviewers?
As a discovery writer, how to complete unfinished novel (which is highly diverted from original plot ) after a time-gap
Is a global DNS record a security risk for phpMyAdmin?
Is there an in-universe reason Harry says this or is this simply a Rowling mistake?
Did HaShem ever command a Navi (Prophet) to break a law?
Should I inform my future product owner that there is a good chance that a team member will leave the company soon?
I reverse the source code, you negate the input!
Debussy as term for bathroom?
Do the villains know Batman has no superpowers?
Removing rows containing NA in every column
Microservices and Stored Procedures
How do I improve in sight reading?
4h 40m delay caused by aircraft inspection, Norwegian refuses EU 261/2004 compensation because it turned out there was nothing wrong with the aircraft
Specifying BOM substitutions / alternatives with Contract Manufacturer (CM)
Persuading players to be less attached to a pre-session 0 character concept
Wired to Wireless Doorbell
Why are Fuji lenses more expensive than others?
Should the pagination be reset when changing the order?
How to send attachment + message body inside one Email
Sending Email in Android using JavaMail API without using the default/built-in appHow to send an object from one Android Activity to another using Intents?How can I send emails from my Android application?How to attach pdf file from assets in email?Send Email IntentHow to nest MimeBodyParts in JavaMail (standard email messages)?Setting Content-Type for MimeMessage?Body message does not appear when sending attachmentsJavaMail content-transfer-encoding issueAndroid JavaMail cancel sending email
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to send email with body and attachment. My problem is i add those using DataHandler
.
I can set only one, so if I put body, and then attachment, only attachment is arriving.
try
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setContent(body, "text/plain");
message.setDataHandler(handler);
MimeBodyPart messageBodyPart = new MimeBodyPart();
if (absolutePath != null)
Multipart multipart = new MimeMultipart();
messageBodyPart = new MimeBodyPart();
String file = absolutePath;
String name = "podpis";
if (fileName != null) name = fileName;
name += ".jpg";
DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(name);
multipart.addBodyPart(messageBodyPart);
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);
catch(Exception e)
Log.e("GMAIL SENDER", e.getMessage());
}
I've been looking for some answers or tips, but I'm not sure if it's me using wrong approach in research, or it's not so obvious.
android javamail mime-message
add a comment
|
I want to send email with body and attachment. My problem is i add those using DataHandler
.
I can set only one, so if I put body, and then attachment, only attachment is arriving.
try
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setContent(body, "text/plain");
message.setDataHandler(handler);
MimeBodyPart messageBodyPart = new MimeBodyPart();
if (absolutePath != null)
Multipart multipart = new MimeMultipart();
messageBodyPart = new MimeBodyPart();
String file = absolutePath;
String name = "podpis";
if (fileName != null) name = fileName;
name += ".jpg";
DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(name);
multipart.addBodyPart(messageBodyPart);
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);
catch(Exception e)
Log.e("GMAIL SENDER", e.getMessage());
}
I've been looking for some answers or tips, but I'm not sure if it's me using wrong approach in research, or it's not so obvious.
android javamail mime-message
1
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29
add a comment
|
I want to send email with body and attachment. My problem is i add those using DataHandler
.
I can set only one, so if I put body, and then attachment, only attachment is arriving.
try
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setContent(body, "text/plain");
message.setDataHandler(handler);
MimeBodyPart messageBodyPart = new MimeBodyPart();
if (absolutePath != null)
Multipart multipart = new MimeMultipart();
messageBodyPart = new MimeBodyPart();
String file = absolutePath;
String name = "podpis";
if (fileName != null) name = fileName;
name += ".jpg";
DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(name);
multipart.addBodyPart(messageBodyPart);
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);
catch(Exception e)
Log.e("GMAIL SENDER", e.getMessage());
}
I've been looking for some answers or tips, but I'm not sure if it's me using wrong approach in research, or it's not so obvious.
android javamail mime-message
I want to send email with body and attachment. My problem is i add those using DataHandler
.
I can set only one, so if I put body, and then attachment, only attachment is arriving.
try
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress(sender));
message.setSubject(subject);
message.setContent(body, "text/plain");
message.setDataHandler(handler);
MimeBodyPart messageBodyPart = new MimeBodyPart();
if (absolutePath != null)
Multipart multipart = new MimeMultipart();
messageBodyPart = new MimeBodyPart();
String file = absolutePath;
String name = "podpis";
if (fileName != null) name = fileName;
name += ".jpg";
DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(name);
multipart.addBodyPart(messageBodyPart);
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);
catch(Exception e)
Log.e("GMAIL SENDER", e.getMessage());
}
I've been looking for some answers or tips, but I'm not sure if it's me using wrong approach in research, or it's not so obvious.
android javamail mime-message
android javamail mime-message
asked Mar 28 at 14:31
SkypeDoggSkypeDogg
12615 bronze badges
12615 bronze badges
1
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29
add a comment
|
1
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29
1
1
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400174%2fhow-to-send-attachment-message-body-inside-one-email%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55400174%2fhow-to-send-attachment-message-body-inside-one-email%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You need to create two MimeBodyParts - one for the text and one for the attachment. See the sendfile.java sample program for a complete example.
– Bill Shannon
Mar 28 at 15:40
You got beer from me mate :)
– SkypeDogg
Mar 29 at 7:29