I'm using the Java EWS library and try to reply to some messages. The main question is - how to find EmailMessage in folder or in mailbox if I only know value of "Message-ID" header of my message.
I try to do something like this:
ExtendedPropertyDefinition p = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "Message-ID", MapiPropertyType.String)
myfolder.findItems(new SearchFilter.IsEqualTo(p, "<1031208507.471.1446200157453.JavaMail.test>"), new ItemView(1))
But result set is aleays empty! Can you help me? Some Java or C# solutions?
You could go for the regular (not extended) property InternetMessageId instead:
ItemView view = new ItemView(1);
String searchstring = "<1031208507.471.1446200157453.JavaMail.test>";
SearchFilter.IsEqualTo filter =
new SearchFilter.IsEqualTo(EmailMessageSchema.InternetMessageId, searchstring);
FindItemsResults<Item> findResults =
service.FindItems(WellKnownFolderName.Inbox, filter, view);
Related
I am trying to sent an file through multi-part form data using Scala and Play 2.4.6.
def sendFile(file: FilePart[TemporaryFile]): Option[Future[Unit]] = {
val asyncHttpClient:AsyncHttpClient = WS.client.underlying
val postBuilder = asyncHttpClient.preparePost(s"${config.ocrProvider.host}")
val multiPartPost = postBuilder
.addBodyPart(new StringPart("access_token",s"${config.ocrProvider.accessToken}"))
.addBodyPart(new StringPart("typename",s"${config.ocrProvider.typeName}"))
.addBodyPart(new StringPart("action",s"${config.ocrProvider.actionUpload}"))
.addBodyPart(new FilePart(???)
}
I'm new on Scala and Play, and i would like to sent file method attribute as new FilePart. Is it possible?
Yes, just like
.addBodyPart(new FilePart("myFile", new File("app/controllers/Application.scala")))
You could find a full example of post in play-scala in my answer here: Sending multi part form data in post method in play/scala
I see from the docs that UserDefinedFunctionResource exists, but I can't find the right call to hook it up to a query job. I'd like to add a resource to gs and register it before running a query using the Java API.
Thanks in advance.
You should add UserDefinedFunctionResource items to your JobConfigurationQuery object. Something like this:
Job content = new Job();
JobConfiguration cfg = new JobConfiguration();
JobConfigurationQuery jobConfigurationQuery = new JobConfigurationQuery();
UserDefinedFunctionResource userDefinedFunctionResource = new UserDefinedFunctionResource();
userDefinedFunctionResource.setResourceUri("gs://mybucket/udf.js");
jobConfigurationQuery.setUserDefinedFunctionResources(Lists.newArrayList(
userDefinedFunctionResource
));
cfg.setQuery(jobConfigurationQuery);
content.setConfiguration(cfg);
Bigquery.Jobs.Insert request = bigqueryService.jobs().insert(projectId, content);
Job response = request.execute();
How to read mail inbox using IMAP protocol and JavaMail and then use local disk to store mails. There is no documentation of mstor.
I try this way but it seems that MStorStore just read local mbox instead of creating and updating it according to the external server passed as params in connect() function. I get error: Folder [Inbox] does not exist.
Session lSession = Session.getDefaultInstance(props);
MStorStore lStore = new MStorStore(lSession , new URLName("mstor:c:/some_path/" + _mailModel.account.login));
lStore.connect(_mailModel.account.imap, _mailModel.account.login, _mailModel.account.password);
Folder lInbox = lStore.getDefaultFolder().getFolder("Inbox");
The questioin is how to create MBox from javax.mail.Store that i could read and update using Mstor.
I don't know if I am answering the right question (or answering a question at all), but, here is a method I wrote in a Scala program that takes an array of javamail Messages (acquired via imap) and writes them to a new mbox file in a directory named "mbox" in the root of my project using MStorStore. The new file is named whatever is passed in the "mboxName" parameter.
def writeToMbox(messages: Array[Message], mboxName: String) {
val mProps = System.getProperties
mProps.setProperty("mstor.mbox.metadataStrategy", "none")
val mSession = Session.getDefaultInstance(mProps)
val mStore = new MStorStore(mSession, new URLName("mstor:mbox"))
mStore.connect
val mFolder = mStore.getDefaultFolder
val localMbox = (new File("mbox", mboxName)).createNewFile
val mbox = mFolder.getFolder(mboxName)
mbox.open(Folder.READ_WRITE)
mbox.appendMessages(messages)
mbox.close(false)
mStore.close
}
I'm looking to leverage RackSpace's CloudFiles platform for large object storage (word docs, images, etc). Following some of their guides, I found a useful code snippet, that looks like it should work, but doesn't in my case.
Iterable<Module> modules = ImmutableSet.<Module> of(
new Log4JLoggingModule());
Properties properties = new Properties();
properties.setProperty(LocationConstants.PROPERTY_ZONE, ZONE);
properties.setProperty(LocationConstants.PROPERTY_REGION, "ORD");
CloudFilesClient cloudFilesClient = ContextBuilder.newBuilder(PROVIDER)
.credentials(username, apiKey)
.overrides(properties)
.modules(modules)
.buildApi(CloudFilesClient.class);
The problem is that when this code executes, it tries to log me in the IAD (Virginia) instance of CloudFiles. My organization's goal is to use the ORD (Chicago) instance as primary to be colocated with our cloud and use DFW as a back up environment. The login response results in the IAD instance coming back first, so I'm assuming JClouds is using that. Browsing around, it looks like the ZONE/REGION attributes are ignored for CloudFiles. I was wondering if there is any way to override the code that comes back for authentication to loop through the returned providers and choose which one to login to.
Update:
The accepted answer is mostly good, with some more info available in this snippet:
RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = cloudFilesClient.unwrap();
CommonSwiftClient client = swift.getApi();
SwiftObject object = client.newSwiftObject();
object.getInfo().setName(FILENAME + SUFFIX);
object.setPayload("This is my payload."); //input stream.
String id = client.putObject(CONTAINER, object);
System.out.println(id);
SwiftObject obj2 = client.getObject(CONTAINER,FILENAME + SUFFIX);
System.out.println(obj2.getPayload());
We are working on the next version of jclouds (1.7.1) that should include multi-region support for Rackspace Cloud Files and OpenStack Swift. In the meantime you might be able to use this code as a workaround.
private void uploadToRackspaceRegion() {
Iterable<Module> modules = ImmutableSet.<Module> of(new Log4JLoggingModule());
String provider = "swift-keystone"; //Region selection is limited to swift-keystone provider
String identity = "username";
String credential = "password";
String endpoint = "https://identity.api.rackspacecloud.com/v2.0/";
String region = "ORD";
Properties overrides = new Properties();
overrides.setProperty(LocationConstants.PROPERTY_REGION, region);
overrides.setProperty(Constants.PROPERTY_API_VERSION, "2");
BlobStoreContext context = ContextBuilder.newBuilder(provider)
.endpoint(endpoint)
.credentials(identity, credential)
.modules(modules)
.overrides(overrides)
.buildView(BlobStoreContext.class);
RestContext<CommonSwiftClient, CommonSwiftAsyncClient> swift = context.unwrap();
CommonSwiftClient client = swift.getApi();
SwiftObject uploadObject = client.newSwiftObject();
uploadObject.getInfo().setName("test.txt");
uploadObject.setPayload("This is my payload."); //input stream.
String eTag = client.putObject("jclouds", uploadObject);
System.out.println("eTag = " + eTag);
SwiftObject downloadObject = client.getObject("jclouds", "test.txt");
System.out.println("downloadObject = " + downloadObject.getPayload());
context.close();
}
Use swift as you would Cloud Files. Keep in mind that if you need to use Cloud Files CDN stuff, the above won't work for that. Also, know that this way of doing things will eventually be deprecated.
I am using Amazon Simple Email Service java API to send mail to receivers.
I am sending URL in mail body inside tag.
My use case demands the user to double click on the URL received to prompt some action. (like confirmation mail)
Problem is the url gets encoded while receiving. On double clicking it gives page not found (404) error.
Original URL : http://something.com/confirm/email=abc#hotmail.com®Key=somekey&confirm=true
When i double click on this URL on mail, the link is opened in address bar as :
http://something.com/confirm/email=abc%40hotmail.com%26regKey=somekey%26confirm=true
I am using AmazonSimpleEmailServiceClient. Code is below :
SendEmailRequest request = new SendEmailRequest().withSource(sourceAddress);
String confirmationURL="http://something.com/confirm/email=abc#hotmail.com®Key=somekey&confirm=true";
List<String> toAddresses = new ArrayList<String>();
toAddresses.add(toEmail);
Destination dest = new Destination().withToAddresses(toAddresses);
request.setDestination(dest);
Content subjContent = new Content().withData("Confirmation Request");
Message msg = new Message().withSubject(subjContent);
// Include a body in both text and HTML formats
Content textContent = new Content().withData("Dear please go to the following URL:"+
confirmationURL+"\n\n");
Content htmlContent = new Content().withData("<p>Dear please go to the following URL:</p>"+
"<p>"+confirmationURL+"</p>");
Body body = new Body().withHtml(htmlContent).withText(textContent);
msg.setBody(body);
request.setMessage(msg)
UPDATE
Just found, this problem is occurring only when recipient email is in hotmail.com. Why microsoft always have to do something differently ? Somebody help !
Use the class java.net.URLEncoder:
String confirmationURL = URLEncoder.encode( "http://something.com/confirm/email=abc#hotmail.com®Key=somekey& confirm=true", "UTF-8");