How To Send HTML Attachment With Android(Java) - java

I'm trying to create POS Android Application, I added feature that after a order submitted the app send the order invoice with email to the customer.
My problem is how to create this invoice with unfixed number of data presented in the invoice so I can send it through email?.
Similar To This One:
by the way I'm using java email API.

You can try StringTemplate to use email templating.

Related

Why am I not able to read the complete email body using Exchange Web Service Java API?

I am using EWS Java API to read and process emails. One such email contains few conversation and a MS Teams meeting information at the end. While reading such an email, the EmailMessage.getBody() returns only the MS Teams meeting information and all the other contents of the email body are ommitted. Sample code below:
EmailMessage message = EmailMessage.bind(service, new ItemId(item.get(nMessagePos).getId().getUniqueId()));
String emailBody = message.getBody().toString()
I tried setting the BodyType property to both HTML and Text and then fetched the body of the email but it still returns only the Meeting invite details.
Is there any specific reason for this and is there a way for me to get the complete email body?
I would try to enable tracing https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-trace-requests-responses-to-troubleshoot-ews-managed-api-applications or look at the actually soap responses your getting it could be a parsing issue at the client side (eg bug in the library). You could also try getting the Mimecontent of the Message instead and then parse back the body from that content. Something like EWSEditor might be useful for trying to diagnose what is going on it will show you what the responses look like and allow you to test mimecontent etc without needing to write any code https://github.com/dseph/EwsEditor/releases.

Sending embedded survey email using MonkeySurvey API

What should be the body-text or body-html when doing a POST request using this API to create messages?
API - https://developer.surveymonkey.com/api/v3/#collectors-id-messages
When I am inserting survey link in the body, I am not getting a clickable embedded question in the mail body like we get when using email collector from console.
Building that format is not currently supported in the API, you can only create with a custom HTML.
That said you can copy a previous message that is in the right format through the API. From the link you specified: https://developer.surveymonkey.com/api/v3/#collectors-id-messages
It shows you can set a from collector/message to copy:
POST /v3/collectors/<collector_id>/messages
{
"from_collector_id": "<any_collector_id>",
"from_message_id": "<message_id_from_provided_collector_id>"
}
That will take a copy of a message you already have created as a template and create a new message. Hopefully that could be a good workaround for your use case.

Add or request a user to add email id to contact list. Is this possible automatically using javamail ?

I have written a java program to send email via SMTP. I would like to know how I can request the user to add my email Id to his address-book/Contact list in his client automatically/manually. Is there a way for me to do it from within my java code. I would like this feature as my emails will not get listed as spam/junk. I am using javamail API.
Thank you,
Nagarajan
NOT POSSIBLE!! You can't do that ,Email will be just mail.Listing your emailid and other things(spam,junk mail) to be done by receiver only.Who receive they have to configure.

Send email via outlook with mail merge using Java

I have a set of contacts in my database. I want my application to build a custom email template for my clients.
My client can set a custom placeholders such as company name, address:
For example:
Dear <<name>>,
This is to inform you that our <<company name>>, located in <<address>> ...
Sincerely,
<<sender>>
After the template is setup I can then use this as a body to my email. Recipients are then fetched from the database.
I am aware of the java.awt.Desktop package which allows me to create a MAIL URI and open it using the user's default email client. The problem is how can I incorporate the mail merge into it? Can you please guide me on existing libraries or solutions to this?
Use the JavaMail library for sending mails. You will find plenty of examples if you search for "JavaMail example", among others: Sending email via Gmail SMTP example. Regarding the placeholders I would simply use the String.replace function.
You will need to control how the variables in the template are setup. I dont think you can parse an arbitrary string and find out if there are variables in it. Hence when a user is adding a variable, make sure that you insert a variable that your program will understand into the email body. Thats a no brainer but thought I'll add it for completeness.
You could save the email body as a velocity template, making sure the variables you added our velocity templating language compliant. Velocity would be easier than string.replace() if there are complicated templates that are being set up. If its a simple one then String.replace() would do.
http://velocity.apache.org/
Next use the java mail library to send it directly from your java program, or launch the default email client of the box using the Desktop class.
EDIT:
If you would like to open outlook then you will need to use Desktop.mail() API. You can pre-populate the to,cc, bcc, subject and body fields in the outlook send email window by constructing an appropriate URI and passing it to Desktop.mail()
mailto:duke#sun.com?SUBJECT=Happy New Year!&BODY=Happy New Year, Duke!
Have a look here for more info:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
For multiple recipients, separating the email addresses with commas should work. If that doesn't, try with a semi colon. Outlook uses semicolon..

Sending HTML formatted email in Android

I have successfully created an Android app that calculates prices and then is able to transfer that data in a preformatted fashion to an email program of the users choice. Depending upon the data the user creates in the app, a string containing the HTML is read into an intent. The code I have for this is:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailText));
QuoteDroid.this.startActivity(emailIntent);
This is all fine and the email is mostly formated correct when I choose the Gmail app, and generally sends mostly correct. The issue I have with this is that I must send it from a non-gmail account for business purposes. When I choose the generic email app on the phone it does not process the HTML properly and when I send the email it is formated in plain text.
I've read through countless articles and forum posts, but to no avail. How do I process the string, containing the HTML, in such a way that the email -after being sent with the built in email app- is viewed properly formated by the receiver?
It's up to the individual mail app to properly handle the String that it receives as the EXTRA_TEXT. A well-behaved mail app will see the mimetype and handle the EXTRA_TEXT appropriately, but not all mail apps do.

Categories