I have an application that periodically polls an 2010 exchange server email inbox for emails with a certain subject.
I am using c#, .Net 3.5 in VS2008. I can successfully connected to, retrieve all the emails I require.
If the Body of the email contains XML which is validated with an xsd, usually this is working fine but when the email has a BodyType of HTML the xml tags are not displayed and it fails the xsd validation.
If I do a show source on the email body the xml tags are all there. My question is, how do I get the actual xml text and not the html text?
I initiate the service using
m_Service = new ExchangeService(ExchangeVersion.Exchange2010);
I am returning the search results using this...
public void getEmails(string searchType)
{
ItemView itemView = new ItemView(int.MaxValue);
SearchFilter searchFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, EmailSubject);
SearchResults = Service.FindItems(GetFolderName(searchType), searchFilter, itemView);
}
and loading the individual emails
foreach (Item item in SearchResults)
{
item.Load();
EmailMessage mes = (EmailMessage)item;
string emailBody = item.Body.Text;
}
it is possible to get PR_HTML MAPI property. You can added as extended property in your request. It works with Exchange Web Services .NET, but should also work with EWS Managed API
Related
Is there a way to create an EWS EmailMessage class instance out of Aspose.Net Email MapiMessage class instance?
I'm trying to use some common logic for email processing.
1) I have a service processing emails coming to an Exchange folder, and everything works just perfectly.
2) Also, I have users able to upload email files (*.msg) into the web app. These emails are processed using Aspose.Net.Email and I have an instance of MapiMessage as an output.
What I can try to do is to use MapiMessage .ToMailMessage() method, which will create an instance of MailMessage from this MapiMessage. But even after that, I wasn't able to find a way to create an EmailMessage to be able to use the processing logic from 1).
Any suggestions?
I have observed your requirements and if I am correctly understanding you are looking for support for interface between Aspose.Email MapiMesaage class and EWS EmailMesage class. These two classes belong to two different APIs and have no interface between them. Aspose.Email for .NET does allow saving as MSG or EML file format and you may load them on your end using EmailMessage class.
I am working as Support developer/ Evangelist at Aspose.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.emailmessage?view=exchange-ews-api
https://apireference.aspose.com/net/email/aspose.email.mapi/mapimessage/constructors/1
My previous VSTO can output the .msg file. But can this be achieved in the new web add-in?
Any code examples?
I am currently using office.js in the front end and EWS managed API in the back end.
Instruction
I have found the above post saying something about that but I cannot integrate into my back end.
Turns out I need to get the itemID first to get the EmailMessage .
ExchangeService service = new ExchangeService();
service.Url = new Uri(ewsUrl);
service.Credentials = new OAuthCredentials(ewsToken);
EmailMessage em = EmailMessage.Bind(service, new ItemId(itemID));
I can use Office.js from the front end to gather those prerequisite info(ewsUrl,ewsTokenitemID)
At this point I can just load the eml by
email.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mimcon = email.MimeContent;
Some of requests to my Web Application return data not in HTML format (JSON).
How to handle this correctly?
I wrote the following page definition:
import com.fasterxml.jackson.databind.ObjectMapper
import geb.Page
class JsonResponse extends Page {
static url = null;
static at = {
true;
}
static ObjectMapper mapper = new ObjectMapper();
static content = {
readTree {
def jsonString = $("pre").text();
mapper.readTree(jsonString)
}
}
}
and it apparently works. But the question is, how correct it is?
It takes data from inside pre tag. This is because I saw this content inside driver.pageSource. Is this correct? May be it is driver-dependent?
I put null into url, since the page has different url depending on query. Is this correct?
Geb is not intended to be used to interact with HTTP API endpoints because it is built on top of WebDriver and hence expects to be used via a browser and on HTML pages.
If you want to test HTTP API endpoints then I would suggest using an http client to back your tests. There are many of them out in the wild, just to name a few in no particular order:
Apache HttpClient
RestAssured - this one is specifically for testing
Ratpack's TestHttpClient - again intended to be used for testing
OkHttp
Unirest
I was able to download the content of a PDF in a geb unit test using the Direct Download API. It is handy because it takes all the cookies from the session but does the download separately from the browser.
Example from that documentation:
Browser.drive {
go "http://myapp.com/login"
// login
username = "me"
password = "secret"
login().click()
// now find the pdf download link
def downloadLink = $("a.pdf-download-link")
// now get the pdf bytes
def bytes = downloadBytes(downloadLink.#href)
}
There are different methods for downloading different kinds of data. See the DownloadSupport API docs.
Because geb uses HttpsURLConnection to connect to an https endpoint instead of using the browser you can have problems with self-signed certificates. I solved that using this Stack Overflow answer.
I agree that Geb is not intended to be used to interact with HTTP API endpoints, but there are some contexts where this can be helpful, so add this snippet here for posterity:
when: 'I retrieve the JSON transaction list'
go '/transaction/transactionList'
then: 'Valid data is retrieved'
JsonSlurper jsonSlurper = new JsonSlurper()
Map<String, List> transactionList = jsonSlurper.parseText(driver.pageSource)
assert transactionList.categories.class == ArrayList
I am using SignalR in MVC to display information in a basic chat type device in MVC. This is all working ok but I want to display information from a Json payload that has been deserialized like this:
Dim iss As IssueObjectClass = JsonConvert.DeserializeObject(Of object)(json)
The information does not have to being displayed does not just have to be an object it could be a variable as well, for example I could also display this:
Dim key = iss.issue.key
I have the code for the connection using the chat hub device which is displaying basic information (Message and username). Is this the way that I should try and display my Json using SignalR. I know that SignalR is used for real-time web applications but I am unsure on how it could display information that has been fired from a webhook as a Json payload.
This is how I am displaying the messages in the chat hub, but I want to display information that is coming from a webhook unrelated to anything that has been typed on the application. I want to display information from a HTTP POST from JIRA:
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
$('#discussion').append('<li><strong>' + encodedName + '</strong>: ' + encodedMsg + '</li>');
$('#discussion').text = encodedMsg;
How can I integrate SignalR with Json to display it?
It's a pretty simple thing to do, and a common case with SignalR. In your code where to receive and deserialize your object, you just have to call something like:
var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.All.broadcastIssue(iss);
On your client you'll have to define a handler this way before you start the connection:
var yourHubProxy = $.connection.yourHub;
yourHubProxy.client.broadcastIssue = function (iss) {
// ...do your stuff...
};
This is very basic code which would need to be better organized, but it should put you on the right track. My advice is you go through the official SignalR documentation, which is extensive and well done, in particular the guides to the APIs.
We planned to migrate the Old Outlook MAPI Logic to EWS Exchange API to send email. I have tested the performance of sending email by triggering 1500 emails (looped) with the attachment of 256 kb PDF File.
For One email it is taking 5 to 6 seconds and overall it is taking 2 hours to send all 1500 emails.
But in other side using Outlook MAPI just taking 45 Minutes to send all 1500 emails.
Am just using basic send email method not much logic added as like below (not an actual code I used).
//Create the email message.
EmailMessage message = new EmailMessage(service);
message.Subject = "Message with Attachments";
message.Body = "This message contains one item attachment.";
message.ToRecipients.Add(UserData.EmailAddress);
//Create another item and use it as an attachment.
ItemAttachment<EmailMessage> itemAttachment1 = message.Attachments.AddItemAttachment<EmailMessage>();
itemAttachment1.Name = "Attached Message Item";
itemAttachment1.Item.Subject = "Message Item Subject";
itemAttachment1.Item.Body = "Message Item Body";
itemAttachment1.Item.ToRecipients.Add(UserData.EmailAddress);
message.SendAndSaveCopy();
Is this the API performance or I need to do some logic to send the email even faster.. Please suggest..
Thanks,
Gunasekaran Sambandhan
Sorry All,
There was a problem in my code. I just modified the way of call from consuming application, as well as a slight change in my .NET COM INTERFACE LIBRARY.
In my case VB 6.0 is the consuming Application.
.NET COM INTERFACE LIBRARY
I just modified the class representation in a way that:
Create Exchange Web service instance method
Send email
From VB 6.0 Application:
Call The Create Exchange Web service instance method
loop thru 1500 emails & call Send email with details
Just a basic discipline that has to be followed but I didn't so I got performance issue. Now I rectified myself & now it is working better that Outlook MAPI. (i.e. Now EWS Only takes 15 minutes)
Thanks,
Gunasekaran Sambandhan