I am writing a very data intensive Metro App where I need to send an email in html format. After googling around I came across this code.
var mailto = new Uri("mailto:?to=recipient#example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.");
await Windows.System.Launcher.LaunchUriAsync(mailto);
This works great for me with one exception. I am generating the body of this email via html string so I have code in my class like this.
string htmlString=""
DALClient client = new DALClient();
htmlString += "<html><body>";
htmlString += "<table>";
List<People> people = client.getPeopleWithReservations();
foreach(People ppl in people)
{
htmlString+="<tr>"
htmlString +="<td>" + ppl.PersonName + "</td>";
htmlString +="</tr>";
}
htmlString +="</table>";
htmlString +="</body><html>";
Now when I run this code the email client opens up. However the result appears as plain text. Is there a way I can have this show up in the formatted html so the html tags and so forth wont display?
Thanks in advance.
It is just not possible to pass HTML to mailto. You could use sharing instead where you can pass HTML code to the default Windows Store Mail App (unfortunately not to the default Desktop Mail Application).
Here is a sample on a page:
public sealed partial class MainPage : Page
{
private string eMailSubject;
private string eMailHtmlText;
...
private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
// Check if an email is there for sharing
if (String.IsNullOrEmpty(this.eMailHtmlText) == false)
{
// Pass the current subject
args.Request.Data.Properties.Title = this.eMailSubject;
// Pass the current email text
args.Request.Data.SetHtmlFormat(
HtmlFormatHelper.CreateHtmlFormat(this.eMailHtmlText));
// Delete the current subject and text to avoid multiple sharing
this.eMailSubject = null;
this.eMailHtmlText = null;
}
else
{
// Pass a text that reports nothing currently exists for sharing
args.Request.FailWithDisplayText("Currently there is no email for sharing");
}
}
...
// "Send" an email
this.eMailSubject = "Test";
this.eMailHtmlText = "Hey,<br/><br/> " +
"This is just a <b>test</b>.";
DataTransferManager.ShowShareUI();
Another approach would be to use SMTP but as far as I know there is no SMTP implementation yet for Windows Store Apps.
Related
I have made small C# WFP application that sends emails with embedded images using C# and Outlook Interop. It seems that many mail clients reacts diffently to emails sent from this application compared to manually created emails where images are pasted directly in using CTRL+V.
I have tried to use OutlookSpy to compare the two emails, but I can't see any difference that could cause the different way the emails are being handled.
When an email sent from the C# application is received in an Outlook Application on an Iphone, the images are blank. It works just fine when the image is manually created and images are pasted in using CTRL+V.
1) How do I make sure that the emails sent from my application are handled the same way as when I manually create an email in Outlook and copy an image using CTRL+V?
If I can make this work, then it should be possible to make the images display correctly in Outlook for Iphone.
2) How does outlook handle an image when it is pasted in using CTRL+V? It seems that it uses Cid, the same way as I do in my application, but how does it refer to the image if it is not attached?
Here is the code for the sample application:
private void SendEmailButton_OnClick(object sender, RoutedEventArgs e)
{
SendMail();
}
public void SendMail()
{
var application = GetOutlookApplication();
MailItem newMail = (MailItem)application.CreateItem(OlItemType.olMailItem);
newMail.To = "!!!EnterValidEmailAddress!!!";
newMail.Subject = "Image test";
//Create image as embedded attachment
Attachment attachment1 = newMail.Attachments.Add(#"C:/SomeImage1.png", OlAttachmentType.olByValue);
string imageCid1 = "SomeImage_1";
//The property Accessor to be able to refer to the image from Email HTML Body using CID
attachment1.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid1);
//Set property Accesor to hide attachment
attachment1.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x7FFE000B", true);
//Refer the attachment using cid
newMail.HTMLBody = String.Format("<img src=\"cid:{1}\">", "google.dk", imageCid1);
newMail.Save();
newMail.Display();
}
public static OutlookApplication GetOutlookApplication()
{
// Start outlook process if it is not startet already
if (!IsOutlookRunning())
{
using (Process p = new Process())
{
p.StartInfo.FileName = "OUTLOOK.EXE";
p.Start();
if (!p.WaitForInputIdle(10000))
Thread.Sleep(5000);
}
}
// Start the outlook application (API)
OutlookApplication oApp = null;
if (Process.GetProcessesByName("OUTLOOK").Any())
{
try
{
oApp = Marshal.GetActiveObject("Outlook.Application") as OutlookApplication;
}
catch (System.Exception)
{
if (oApp == null)
oApp = new OutlookApplication();
}
return oApp;
}
oApp = new OutlookApplication();
return oApp;
}
private static bool IsOutlookRunning()
{
Process[] p = Process.GetProcessesByName("Outlook");
return p.Length != 0;
}
Make sure that you get a well-formed HTML markup finally. The following line of code just adds the <a> tag to the end of body string:
newMail.HTMLBody += String.Format("<img src=\"cid:{1}\">", "google.dk", imageCid1);
Instead, you need to find a right place for the image between the <body> and </body> tags.
I am creating a web app. where I want be able to incorporate Google Maps into 1 of my pages.
From what I have read in other places, the easiest think is to place a web browser onto the form but there is no 'Web Browser' in the tool-box.
What I am trying to do is to insert a location into a textbox(ie. London) and insert a type of sport(ieCycling) and the resultant map shows up. Is there any other way in doing this in C# other than using the web browser tool.
Here is my code:
protected void btnSearch_Click(object sender, EventArgs e)
{
string sport = txtSport.Text;
string location = txtLocation.Text;
try
{
StringBuilder queryAddrress = new StringBuilder();
queryAddrress.Append("https://maps.google.ie/");
if (sport != string.Empty)
{
queryAddrress.Append(sport+","+"+");
}
if (location != string.Empty)
{
queryAddrress.Append(location + "," + "+");
}
Panel1.Navigate(queryAddrress.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(),"Error");
}
} protected void btnSearch_Click(object sender, EventArgs e)
{
string sport = txtSport.Text;
string location = txtLocation.Text;
try
{
StringBuilder queryAddrress = new StringBuilder();
queryAddrress.Append("https://maps.google.ie/");
if (sport != string.Empty)
{
queryAddrress.Append(sport+","+"+");
}
if (location != string.Empty)
{
queryAddrress.Append(location + "," + "+");
}
Panel1.Navigate(queryAddrress.ToString());
}
I tried to put the address into a panel but this is clearly wrong. Any help would be greatly appreciated!
It seems like you are very confused and mixing ASP.NET Web Forms with Windows Forms.
Specifically, MessageBox.Show() would open a Windows message box, not a browser window. And it would happen on the server side for whatever user your web server runs as. Probably not the desired intention. Also, you can't "put a web browser" onto a page. There is a WebBrowser control for Windows Forms, which embeds a minified version of Internet Explorer into a Windows application. But again, probably not what you want.
ASP.NET can be used as if it were just a normal HTML site. So find some Google Maps tutorials for HTML and follow those.
I wanted to write to a NFC tag information about which application should start and add some text data to it. LaunchApp was working fine till I want to transmitt this additional message. When I added additional message LaunchApp stopped working. It is better explained in the code at the end of: private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId)
How to make LaunchApp work and pass this string: GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text to the tag.
public partial class MainPage : PhoneApplicationPage {
private long subscribedMessageID, publishedMessageId;
private ProximityDevice proximityDevice;
public MainPage() {
InitializeComponent();
createTagService();
}
private void createTagService() {
string appId = "{39989b95-a54a-4810-b4ee-35b33265a680}";//HomeSecurityClient Application ID
string args = "param=test";
string launchAppMessage = args + "\tWindowsPhone\t" + appId;
DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf16LE };
dataWriter.WriteString(launchAppMessage);
proximityDevice = ProximityDevice.GetDefault();
proximityDevice.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer(), LaunchMesssageTransmitted);
}
private void LaunchMesssageTransmitted(ProximityDevice sender, long publishedMessageId) {
sender.StopPublishingMessage(publishedMessageId);
/* Deployment.Current.Dispatcher.BeginInvoke(() => {
DataWriter dataWriter = new DataWriter() { UnicodeEncoding = UnicodeEncoding.Utf8 };
dataWriter.WriteString(GlobaIPTextBox.Text + ";" + PortTextBox.Text + ";" + LocalIPTextBox.Text);
sender.PublishBinaryMessage("Windows:WriteTag.NetworkData", dataWriter.DetachBuffer(), networkDataMessageTransmitted);
});*/ //IF I UNCOMMENT THIS TO TRANSMITT ADDITIONAL MESSAGE LAUNCHING APP STOPS WORKING
}
private void networkDataMessageTransmitted(ProximityDevice sender, long publishedMessageId) {
sender.StopPublishingMessage(publishedMessageId);
Deployment.Current.Dispatcher.BeginInvoke(() => {
MessageBox.Show("The data is written");
});
sender.StopPublishingMessage(publishedMessageId);
}
}
You can't write two seperate NDEF messages onto one tag. The last message will always overwrite any previous message. What you can do, however, is to write both records (the LaunchApp record and your customized record) to the tag within one NDEF message. For this to work, you would use the PublishBinaryMessage() method together with the message type "NDEF:WriteTag". That way you can pass the properly formatted(!) NDEF message to the tag. A way to create a properly formatted NDEF message would be to use the free NFC library from http://ndef.mopius.com/.
I need to create a qrreader with windows phone.
Xzing examples only print to video the qr string captured,
I need an example of how to understand if this string is a vcard and, consequently, save it in contact, or if it is a link and open it in the browser.
private void ScanPreviewBuffer()
{
try
{
_photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
var result = _reader.decode(binBitmap);
Dispatcher.BeginInvoke(() => CheckQr(result.Text));
}
catch { }
}
private void CheckQr(string qrString)
{
VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(500));
MessageBox.Show(qrString);
/* CONTROLS HERE */
}
Obviously you have to start by parsing the qrString content to get what you want, i think we'll both agree on that point ;)
So the main issues are :
Determining formats (url or vcard)
Parsing them (if needed)
Using them to trigger wanted actions
1. About vCard
To determine if you qrString holds a vCard, maybe you could just try to match (with string.Contains or string.StartsWith methods) the vCard header which is BEGIN:VCARD and always seems to be the same from one version to another (see wikipedia).
For Windows Phone 7, there's no builtin features to parse vCards, so you have to do it by yourself or you could try to use the vCard library For Windows Phone. It would be used this way :
byte[] byteArray = Encoding.UTF8.GetBytes(qrString);
using (StreamReader reader = new StreamReader(new MemoryStream(byteArray)))
{
vCard card = new vCard(reader);
// access here card.PropertyFromvCard to get the information you need
}
There's not so much documentation about it, but sources are available on codeplex, so you'll probably find all the property names and samples you need.
For Windows Phone 8, the builtin ContactInformation.ParseVcardAsync method could help you to parse your qrString content (here is an official tutorial)
Then you need to finally create your contact :
If you're developping your App on Windows Phone 7, there's no way to create a contact directly from your application. You need to use the "save contact task" and pre-populate the fields you need. Here's an example :
SaveContactTask saveContactTask = new SaveContactTask();
saveContactTask.Completed += new EventHandler<SaveContactResult>(saveContactTask_Completed);
saveContactTask.FirstName = "John"; // card.PropertyFromvCard and so on...
saveContactTask.LastName = "Doe";
saveContactTask.MobilePhone = "2065550123";
saveContactTask.Show();
If you're developping on Windows Phone 8 (and it doesn't seem to be the case given your question tags), you can create a Custom contact store and write directly into it
2. About URLs
To know if you're dealing with an URL or not, i would advice you to follow suggestions coming with this SO answer. To make a long story short, here's the code you could use or at least something similar :
static bool IsValidUrl(string qrString)
{
Uri uri;
return Uri.TryCreate(urlString, UriKind.Absolute, out uri)
&& (uri.Scheme == Uri.UriSchemeHttp
|| uri.Scheme == Uri.UriSchemeHttps
|| uri.Scheme == Uri.UriSchemeFtp
|| uri.Scheme == Uri.UriSchemeMailto
/*...*/);
}
And finally to open your URL into a web browser (if it is a valid one of course), you could use the WebBrowser task or embed a true WebBrowser into your application with the WebBrowser control and make good use of it.
ZXing has a class called ResultParser with a static method parseResult.
The ResultParser supports some common content formats like vCard, vEvent, URL, etc.
It gives you as a result an instance of AddressBookParsedResult for vCard content back.
ParsedResult parsedResult = ResultParser.parseResult(result);
I am wondering how could I implement emoticons in my chat room whilst I talk to other people/Friends.
Here is what I have to send my message out:(Chat Client's Form)
private Image smiley = Image.FromFile(Application.StartupPath.ToString() + "\\Smiles\\ConfusedSmiley.png");
private void SendMsg_Click(object sender, EventArgs e)
{
if (WriteMsg.Text != "")
{
int _index;
_index = WriteMsg.Find(":S");
if (_index != -1)
{
WriteMsg.Select(_index, ":S".Length);
WriteMsg.InsertImage(smiley);
}
mConnection.SendMessage(".msg : " + WriteMsg.Text);
WriteMsg.Text = "";
}
}
This is my connection with the Stream output:
public void SendMessage(string Msg)
{
Console.WriteLine(">>"+Msg);
Outgoing.WriteLine(Msg);
Outgoing.Flush();
}
Now, as you can see, in my Chat Form's "SendMsg_Click", I have the type of image that should be sent when you type :S, well, all it does is send empty text, no image. I am currently using, Khendys.Controls "ExRichTextBox" to try and get the images working. Now, my other question is, do I need to add the same thing to the Server Client? If I only do it through the chat client, it would probably have to be in the server client as well is what I'm saying.
You need not to send the image (emotiocons) when they are used in the message. You should have the same set of images in client as well as server. Suppose you send from client :), then, in server side you need to replace the string with the local image (emoticon) same apply in the reverse.