Html e-mail not being updated fast enough for smtp - html

Is there a known issue with SMTP and timing? I have included some code below that basically sends a birthday greeting to someone, along with a horoscope and other people that share their birthday (for fun).
I use Regex replace to get both elements, horoscope and other people, from other methods and insert them into the HTML document between a pair of "p" tags. I am positive that those methods work, and I am positive that the HTML document is being properly reformatted (according to the console, which prints out my new HTML document in another test of mine). I am thinking that maybe my problem is that the e-mail is sent off before the replacement has a chance to happen, but I could very easily be was off base. If anyone has had this issue before or knows the cause of it, I would be very appreciative. TIA.
public void formatHTMLTest()
{ using (StreamReader reader = File.OpenText("../../BirthdayMessage.htm"))
{
//Format the body
//Format the Famous People
string html = reader.ReadToEnd();
string replacePattern1 = "<!--INJECT FAMOUS PEOPLE HERE-->";
List<string> famousPeople = new List<string>();
famousPeople.Add("test1");
famousPeople.Add("test2");
famousPeople.Add("test3");
StringBuilder famousSB = new StringBuilder();
foreach (string person in famousPeople)
{
famousSB.Append(person + ", ");
}
int length = famousSB.Length;
famousSB.Remove(length - 2, 2);
string famousString = famousSB.ToString();
string html1 = Regex.Replace(html, replacePattern1, famousString);
//Format the Horoscope
string horoscope = "FOO.";
string replacePattern2 = "<!--INJECT HOROSCOPE HERE-->";
string html2 = Regex.Replace(html1, replacePattern2, horoscope);
//Configuring the SMTP client
SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("barfoo#sender.com", "senderPass");
smtp.Host = "mysmtp";
//Set up email that is sent to the client
MailMessage clientEmail = new MailMessage();
clientEmail.From = new System.Net.Mail.MailAddress("barfoo#sender.com");
clientEmail.To.Add(new MailAddress("foobar#recipient.com"));
clientEmail.Subject = "Happy Birthday!";
clientEmail.IsBodyHtml = true;
clientEmail.Body = html;
//using (smtp as IDisposable)
{
smtp.Send(clientEmail);
clientEmail.Dispose();
}
}
}
I guess this goes without saying since I was able to get an e-mail, but just for clarity's sake, the SMTP has no issues also. I am fully able to receieve e-mails. The issue is that they do not contain the replaced html that appears in my console for other tests.
Also, any other things you see wrong with this code (optimizations, etc), don't hesitate to comment. I'm always willing to learn! Thanks

You are injecting the string html into the body. It should be html2?

Related

Getting PidLidEndRecurrenceDate value using Ews

What is the correct way of getting PidLidEndRecurrenceDate values using Ews. below code does not give proper result. property details that i am looking is https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxprops/816378cf-07ef-4926-b7d2-53475792403d
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("X#X.com", "XXX");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ItemView view = new ItemView(10);
Guid MyPropertySetId = new Guid("{6ED8DA90-450B-101B-98DA-00AA003F1305}");
int intValue = Convert.ToInt32("0x0000000F", 16);
ExtendedPropertyDefinition extendedPropertyDefinition =
new ExtendedPropertyDefinition(MyPropertySetId, intValue, MapiPropertyType.Integer);
view.PropertySet =
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, extendedPropertyDefinition);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
if (item.ExtendedProperties.Count > 0)
{
// Display the extended name and value of the extended property.
foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
{
Console.WriteLine(" Extended Property Name: " + extendedProperty.PropertyDefinition.Name);
Console.WriteLine(" Extended Property Value: " + extendedProperty.Value);
}
}
}
That property is set on the Meeting invite messages only not on the Master instance of the Calendar Appointments which is what you seem to be looking at. For the Master instances you should just be able to use the strongly typed property https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.recurrence.enddate?redirectedfrom=MSDN&view=exchange-ews-api#Microsoft_Exchange_WebServices_Data_Recurrence_EndDate
It you wanted to view the property you have above search the SentItems Folder for invites with recurrences (with Enddates) and that's where you will see it. Or probably easier just look at the messages with a Mapi editor like OutlookSpy or MFCMAPI and you will see the properties available.

LibreOffice Basic Macro command converting Calc cellRange to RTF/HTML

My goal is to fill a LibreOffice calc sheet, and silently send a cell range by email when the user clicks the send-off button (and once more to confirm).
So there is three part to this.
A push button with a request to confirm. (Easy and done.)
Select Cell Range and turn it into rich text format (Haven't yet found)
Send rich text email from within the sheet. (Will tackle the "silent" part later)
I tried copying the range to the clipboard with unoService but it seemed over-complicated and full of errors.
Here's what I have:
''''Send by e-mail enriched text
Sub Main
Dim Doc, Sheet, Range, Rtf, Exec as Object
End Sub
'Confirm it
Sub SendTableApproval
If MsgBox ("Ready to email?", MB_YESNO + MB_DEFBUTTON2) = IDYES Then
CopyTable()
End If
End Sub
'Copy it
Sub CopyTable
Doc = ThisComponent
View = Doc.CurrentController
Frame = View.Frame
Sheet = Doc.Sheets.getByIndex(0)
Range = Sheet.getCellrangeByName("a1:f45")
Exec = createUnoService("com.sun.star.frame.DispatchHelper")
View.Select(Range)
Cells = View.getTransferable()
Exec.executeDispatch(Frame, ".uno:Deselect", "", 0, array())
'SimpleMailTo(Cells)
End Sub
'Mail it
Sub SimpleMailTo(body)
Dim launcher as object
Dim eAddress, eSubject, eBody, aHTMLanchor as string
launcher = CreateUnoService("com.sun.star.system.SystemShellExecute")
eAddress = "tu#domo.eg"
eSubject = "Cotidie agenda futuendane"
eBody = body
aHTMLanchor = "mailto:" & eAddress & "?subject=" & eSubject & "&&body=" & eBody
launcher.execute(aHTMLanchor, "", 0)
End Sub
I still do not know after three days of research over methods, properties, uno.
My question is, simply put, How can I convert a transferable content to HTML/RTF?
Simply copying and pasting into an email produces the result you are asking for. The code on the LibreOffice side should look like this.
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
It sounds like you already tried this, but something didn't work. Perhaps you could elaborate on what went wrong.
Another approach would be to write the spreadsheet to a temporary HTML or XHTML file. Then parse the temporary file to grab the part needed for the email.
AFAIK there is no such command to turn a cell range into rich text format with UNO. To do it that way, you would need to loop through each text range of each cell, read its formatting properties and then generate the HTML yourself.
EDIT:
Good idea about XTransferable. The following Java code adapted from the DevGuide gets an HTML string and then prints it. I believe this would be a good solution for your needs.
public void displayHTMLFromClipboard()
{
try
{
Object oClipboard = xMCF.createInstanceWithContext(
"com.sun.star.datatransfer.clipboard.SystemClipboard", xContext);
XClipboard xClipboard = (XClipboard)
UnoRuntime.queryInterface(XClipboard.class, oClipboard);
XTransferable xTransferable = xClipboard.getContents();
DataFlavor[] aDflvArr = xTransferable.getTransferDataFlavors();
System.out.println("Available clipboard formats:");
DataFlavor aChosenFlv = null;
for (int i=0;i<aDflvArr.length;i++)
{
System.out.println(
"MimeType: " + aDflvArr[i].MimeType +
" HumanPresentableName: " + aDflvArr[i].HumanPresentableName );
if (aDflvArr[i].MimeType.equals("text/html"))
{
aChosenFlv = aDflvArr[i];
}
}
System.out.println("");
try
{
if (aChosenFlv != null)
{
System.out.println("HTML text on the clipboard...");
Object aData = xTransferable.getTransferData(aChosenFlv);
String s = new String((byte[])aData, Charset.forName("ISO-8859-1"));
System.out.println(s);
}
}
catch (UnsupportedFlavorException exc)
{
exc.printStackTrace();
}
}
catch(com.sun.star.uno.Exception exc)
{
exc.printStackTrace();
}
}
If you plan to use Basic, it might be a good idea to do some research into the proper way to convert bytes. The code I have below seems to work but is probably unreliable and unsafe, and will not work for many languages. A few of my initial attempts crashed before this finally worked.
Sub DisplayClipboardData
oClipboard = createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
xTransferable = oClipboard.getContents()
aDflvArr = xTransferable.getTransferDataFlavors()
For i = LBound(aDflvArr) To UBound(aDflvArr)
If aDflvArr(i).MimeType = "text/html" Then
Dim aData() As Byte
aData = xTransferable.getTransferData(aDflvArr(i))
Dim s As String
For j = LBound(aData) to UBound(aData)
s = s & Chr(aData(j)) 'XXX: Probably a bad way to do this!
Next j
Print(s)
End If
Next
End Sub
One more suggestion: Python might be a better language choice here. In many ways, using Python with LibreOffice is easier than Java. And unlike Basic, Python is powerful enough to comfortably handle byte strings.

Embedding SSRS 2016 reports into another webpage without iFrame?

Reporting-services 2016 (currently only available as a technical preview) comes with big-upgrades including HTML5 rendering and compliance. See: https://msdn.microsoft.com/en-us/library/ms170438.aspx
My desire is to embed SSRS 2016 reports into another webpage using native mode (no Sharepoint or aspx, just pure HTML5).
The traditional fashion to do this is to use an iFrame.
This is an half-way okay method as it's possible to remove the toolbar, hide parameters etc but still you end up losing a lot of control over the document. This is a cross-site implementation from a different domain so I can't manipulate the contained iFrame document as I please.
Does there exist an official way to embed the report element 'natively'?
I could envision a URL parameter option like rs:Format=REPORTDIV which serves me a html element.
I also tried fetching the report as an image (rs:Format=IMAGE&rc:OutputFormat=PNG) but the resulting PNG has a huge white frame (even when setting background to transparent in Report Builder) around the report element which is a no-go.
This should work. It should work outside of the environment as well as it embeds the images from memory instead of fetching them from the database
// Create service instance
ReportExecutionServiceSoapClient rsExec = new ReportExecutionServiceSoapClient(binding, endpoint);
rsExec.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
rsExec.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
ReportingServices.Extension[] extentions = null;
ReportingServices.TrustedUserHeader trustedUserHeader = new ReportingServices.TrustedUserHeader();
rsExec.ListRenderingExtensions(trustedUserHeader, out extentions);
string reportPath = "/Untitled";
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
ReportingServices.ServerInfoHeader serverInfo = new ReportingServices.ServerInfoHeader();
string historyID = null;
rsExec.LoadReport(trustedUserHeader, reportPath, historyID, out serverInfo, out execInfo);
//Get execution ID
execHeader.ExecutionID = execInfo.ExecutionID;
string deviceInfo = null;
string extension;
string encoding;
string mimeType;
ReportingServices.Warning[] warnings = new ReportingServices.Warning[1];
warnings[0] = new ReportingServices.Warning();
string[] streamIDs = null;
string format = "HTML5";
Byte[] result;
rsExec.Render(execHeader, trustedUserHeader, format, deviceInfo, out result, out extension, out mimeType, out encoding, out warnings, out streamIDs);
var report = Encoding.UTF8.GetString(result);
int streamIdCount = streamIDs.Length;
Byte[][] imageArray = new Byte[streamIdCount][];
String[] base64Images = new String[streamIdCount];
for (int i = 0; i <= streamIdCount - 1; i++)
{
Byte[] result2;
string streamId = streamIDs[i];
rsExec.RenderStream(execHeader, trustedUserHeader, format, streamId, deviceInfo, out result2, out encoding, out mimeType);
imageArray[i] = result2;
base64Images[i] = Convert.ToBase64String(result2);
string replace = string.Format("https://<reportserver>/ReportServer?%2FUntitled&rs%3ASessionID={0}&rs%3AFormat={1}&rs%3AImageID={2}", execInfo.ExecutionID, format, streamId);
string src = string.Format("data:{0};charset=utf-8;base64, {1}", mimeType, base64Images[i]);
report = report.Replace(replace, src);
}

Can Microsoft Translator answer "does a word exist" queries?

I want to know if the API can do something like this:
I send a word in an predetermined language
API answer if the word exist in that language.
To add some context to the question, the idea is to develop a Scrabble like game, and I'm investigating a method to detect valid words, for all (or most common) languages that is.
I've already asked for a solution in one of their forums, but they are kind of dead.
I tested the MS translator service.
var result = MST.TranslateText("xyz", "en", "de"); // custom routine that calls MS service
var result2 = MST.TranslateText("dog", "en", "de");
var result2 = MST.TranslateText("sdfasfgd", "en", "de");
Result = XYZ // source xyz
Result2 = Hund // source dog
Result3 = sdfasfgd // sdfasfgd
Looks like when not found or a translation is not possible the string
is returned untouched.
The only strange behavior i've noted is conversion to uppercase for Some 3 letter scenarios that
arent obvious TLAs in either langauge.
public string TranslateText(string sourceText, string fromLang, string toLang) {
var httpRequestProperty = GetAuthorizationRequestHeader();
var msTransClient = new TranslatorService.LanguageServiceClient();
// Creates a block within which an OperationContext object is in scope.
using (var scope = new OperationContextScope(msTransClient.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
//Keep appId parameter blank as we are sending access token in authorization header.
var translationResult = msTransClient.Translate("", sourceText, fromLang, toLang, "text/plain", "");
return translationResult;
}
}

Issue with OAuth and Flickr - cannot request token

I am currently trying to request a token from Flickr to then be able to do some calls to their OAuth methods. I know I must be doing something wrong, for I get a reply that the signature is wrong, but honestly I followed their instructions (http://www.flickr.com/services/api/auth.oauth.html, http://www.flickr.com/services/api/auth.oauth.html#request_token, http://www.flickr.com/services/api/flickr.auth.oauth.getAccessToken.html) but I still get an error:
oauth_problem=signature_invalid&debug_sbs=GET&http%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3D%26oauth_consumer_key%3Da0f20d2c9b0a142848cffdf9d9a5ad78%26oauth_nonce%3DFCBB713F-581E-4BC6-42FF-C50252D839EC%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1330450158%26oauth_version%3D1.0
I don't get how to create that signature nor how to put it in the request, could anybody point me in the right direction? Thanks!
I am currently working with AS3, below is my code:
// request params
var now:Date = new Date();
var requestParams:Object = {};
requestParams.oauth_callback = ""; // there is no callback, it's a desktop application
requestParams.oauth_consumer_key = API_KEY;
requestParams.oauth_nonce = UIDUtil.getUID(now);
requestParams.oauth_timestamp = String(now.time).substring(0, 10);
requestParams.oauth_signature_method = "HMAC-SHA1";
requestParams.oauth_version = "1.0";
// create an array to sort param names alphabetically
// mandatory to create signature
var sortedRequestParamNames:Array = [];
var name:String;
for(name in requestParams)
{
sortedRequestParamNames.push(name);
}
sortedRequestParamNames.sort();
// create signature
// see http://www.flickr.com/services/api/auth.spec.html#signing
var oauthSignature:String = API_SECRET;
var i:uint;
var numParams:uint = sortedRequestParamNames.length;
var paramName:String;
for(i = 0; i < numParams; i++)
{
paramName = sortedRequestParamNames[i];
oauthSignature += paramName + convertToPercentEntities(requestParams[paramName]);
}
oauthSignature = MD5.hash(oauthSignature);
// build request
var tokenRequestString:String = REQUEST_TOKEN_URL;
for(i = 0; i < numParams; i++)
{
paramName = sortedRequestParamNames[i];
tokenRequestString += (i == 0) ? "?" : "&";
tokenRequestString += paramName + "=" + requestParams[paramName];
}
tokenRequestString += "&oauth_signature=" + oauthSignature;
var tokenRequest:URLRequest = new URLRequest(tokenRequestString);
tokenRequest.method = URLRequestMethod.GET;
// load request
initLoader();
_loader.addEventListener(Event.COMPLETE, requestTokenLoadedHandler);
_loader.load(tokenRequest);
Basically, you need to use the HMAC-SHA1 algorithm instead of an MD5. I'll walk you through it.
1. Create the signature base string
You seem to be doing that (but you are assigning it directly to the signature variable). Compiling the base string is done by concatenating three different parts.
Convert the HTTP Method to uppercase and set the base string equal to this value. Example: GET
Append the '&' character to the base string.
Percent encode the URL (without parameters) and append it to the base string. Example: http%3A%2F%2Fexample.com%2Frequest
Append the '&' character to the base string.
Percent encode the sorted parameter string and append it to the base string.
It should end up looking like this:
GET&http%3A%2F%2Fexample.com%2Frequest&a2%3Dr%2520b%26a3%3D2%2520q
%26a3%3Da%26b5%3D%253D%25253D%26c%2540%3D%26c2%3D%26oauth_consumer_
key%3D9djdj82h48djs9d2%26oauth_nonce%3D7d8f3e4a%26oauth_signature_m
ethod%3DHMAC-SHA1%26oauth_timestamp%3D137131201%26oauth_token%3Dkkk
9d7dh3k39sj
Now you're done with the signature base string. Lets move on to
2. Figuring out your signing key.
Your signing key is on this format: CONSUMER_SECRET + "&" + TOKEN_SECRET. But since you do not have a token yet, the signing key is the consumer secret and an ampersand. Like this: CONSUMER_SECRET + "&".
For all requests, except the first one your will have a token though, either a request token or an access token.
3. Combine the key and the base string using the HMAC-SHA1 algorithm.
I have used http://code.google.com/p/as3crypto/ when signing with AS3. You can even test its HMAC-SHA1 algorithm on this demo page: http://crypto.hurlant.com/demo/.
Use the base string as input, and the signing key as key to the HMAC-SHA1 algorithm.
The output of the HMAC-SHA1 algorithme will be a binary string which needs to be base64 encoded to produce the final signature. It should look something like this:
NYIQGEwIomgCuVOIA28pMDMID78=
This should be send with the request as the oauth_signature parameter.
I had problem with it too, ended up using FlickrNet API.
http://flickrnet.codeplex.com/