I'm using sendgrid java web api client from their website to send mail through the web api gateway. My problem is that i can only send one message per request and i usually have need to send 1000-1500 messages at a time which are all different in content, so I just send them in a loop. However, this makes 1000-1500 api request which is very slow.
Is it possible to send multiple individual different emails in one request?
This is a bit of a workaround, but you could batch different emails together into one request by using the substitution property of the X-SMTPAPI header. In your email body, include only the substitution token, e.g. %content%. Then pass your actual content in the header, e.g.
{
"to": [
"john.doe#gmail.com",
"jane.doe#hotmail.com"
],
"sub": {
"%content%": [
"Here is the content for the email to john.doe",
"And this is some different content for jane.doe"
]
}
}
Yes, it is:
https://sendgrid.com/docs/Integrate/Code_Examples/java.html
You can just keep adding multiple 'tos' to your email, like this:
email.addTo("anemail#example.com")
However, you want to do it via adding multiple BCCs instead so you don't give away everyones email address.
email.addBcc("anemail#example.com")
Related
I am working on receiving mails in my springboot application. In order to fetch and store the receive mails. I am using imap mail listener. There are two types of mails which I am storing. One is multipart payload type and the other is string payload type.
After receiving mail I am trying to send an auto-generated mails using java mail.
The issue which I am facing is worst case scenario of generating auto-reply from my application i.e infinite loop.
Can someone help ow can I differentiate between a normal mail received and auto-reply received in my mail box and generate auto-replies from my system only for those mails which are not auto-reply type.
It would be nice if explained via code for headers check. I came across through few headers like x-Autosubmitted. But they are returning null if I am trying to print the values in console.
The auto-submmitted markers are described below that you may find helpful:
auto-generated - Indicates that a message was generated by an automatic process, and is not a direct response to another message.
auto-replied - Indicates that a message was automatically generated as a direct response to another message.
auto-notified - Indicates that a message was generated by a Sieve notification system.
no - Indicates that a message was NOT automatically generated, but was created by a human. It is the equivalent to the absence of an Auto-Submitted header altogether.
The RFC 2822 states the following:
Though optional, every message SHOULD have a "Message-ID:" field.
Furthermore, reply messages SHOULD have "In-Reply-To:"
So, you may check for the "In-Reply-To:" value in the header.
Also you may add your own value to the outgoing email, so you may distinguish between an automatically generated reply from your system and manually created.
I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement
POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.
The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)
Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)
Now the Second Response should come from Server with Status 200 OK and Thumbnail URL
is it feasible with one REST API? (Async/similar)
or should I split it to 2 API calls, Please suggest
No. In http, one request gets one response. The client must send a second request to get a second response.
You can use WebSockets for that.
If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.
You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.
On the client side second request must be callback of first request.
The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).
You can return two response using custom middlewares in asp.net (however not recommended).
Return response from one middleware and subsequently you can invoke next middleware and return second response from second middleware
I'm trying to create a simple test plan in JMeter to send data over JMS, using a Publisher and a Subscriber. I've got a Java Request which returns a SampleResult object containing a list of subresults, each containing a String ("Hello, world!" + count), and I want to be able to send these Strings over JMS, but I can't work out how to access them.
Everything is working fine in isolation, but how can I plug the result that my Java Request spits out into my Publisher so it can be sent?
Add a Regular Expression Extractor as a child of your Java Request:
You can then use this in your JMS Sampler:
${data}
HelloI've built an Android application that uses PubNub to create a chat channel between each user. I would like to be able to identify which users have sent which messages. Currently the login of my app is handled by Parse so each user has a unique username. I found some documentation and example code where rather than sending just the message string, an object was set up that contained the UUID and message string as two different objects that could then be extracted on the subscribe side but from what I could tell this was only in the PubNub javascript code not the Java code for Android.Right now i'm thinking that the only way for me to do this is to attach the UUID/username to the beginning of my message string with a special character to seperate the UUID and the message and then split it up and read it in on the subscribe side. For example String message = "uuidhere_messagehere";. Is this the correct way to approach this or is there a better, more convenient way of doing this?thanks
Correct - PubNub does not inject anything into your messages so you will need to include the sender id within each message that is published. Here's is a simple example of a JSON message you might publish:
{'sender_id':'user_333', 'msg':'this is my msg to you-hoo-hoo'}
Of course, the JSON message can have any key/value pairs you require.
I am creating a REST API on top of an existing application. One of the features takes in a json data along with a file uploaded by the user.
I am unsure how to send a file AND json data in the same request to the REST API?
I have the json part working and I test that using curl:
curl -XPOST http://localhost:8080/myapp/foo -d '{"mydata": {
"name": "somename",
"gender": "male"
}}'
//I would like to send an image (say, profile image) with the above request as well.
I'm using a grails application so I get this data in my controller like so: new Foo(params.mydata).
Question
Is it possible to send JSON data and a file in the same request to the API? If so, how can I do it using curl or REST Console (chrome extension)
What would be the contentType of this request?
I'm open to sending data in another format if it means that I can send file and other data (strings) within the same request. I'm not tied on JSON
Update
I found another SO question which is asking the same thing. From the answer to that question it seems there are only three choices and none of which say that its possible to send both, json data and file, within the same request. Which is very discouraging...I will keep this question open to see if anyone has other ideas.
I think the "right" way to do this is with a multipart message. That way, you can post up both the JSON and the Image with their corresponding correct MIME type. The wikipedia article on multipart mime types has an example of what this would look like. It looks like both Apache httpcommons and Jersey support this sort of thing, and apparently curl does too!