展望VSTO C#做专为HTML网址 [英] Outlook VSTO C# Make post to html url
问题描述
我使用VS2010 C#做插件的Outlook 2010。
我的插件的目的是从新的电子邮件抢要,CC,BC当
自定义按钮从色带按下并张贴到外部URL(其中
发生在POST请求)。类似如何在HTML表单/ JSP可以张贴输入
A不同的网页(URL)。
到目前为止,我可以抢要,CC,BC和其存储在一个字符串变量。但我并不
知道如何做一个帖子外部URL。
任何帮助将不胜感激。谢谢
下面是我为我的功能代码至今:
公共无效makePost(对象项目,楼盘布尔取消)
{
Outlook.MailItem myItem =项目为Outlook.MailItem;
如果(myItem!= NULL)
{
串emailTo = myItem.To;
串emailCC = myItem.CC;
串emailBCC = myItem.BCC;
如果(emailTo == NULL和放大器;&安培; emailCC == NULL和放大器;&安培; emailBCC == NULL)
{
MessageBox.Show(没有收件人检查);
}
,否则
{
串emailAdresses = string.Concat(emailTo,;,emailCC,;,emailBCC);
//做一些事情在这里张贴的字符串(emailAddresses)一些网址。
}
}
}
您需要使用的WebRequest / < A HREF =http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx相对=nofollow> HttpWebRequest的类,例如:
HttpWebRequest的要求= HttpWebRequest.Create(http://google.com/postmesmth)作为HttpWebRequest的;
request.Method = WebRequestMethods.Http.Post;
request.Host =google.com
request.UserAgent =Mozilla的/ 5.0(Windows NT的6.1; WOW64; RV:22.0)的Gecko / 20100101火狐/ 22.0;
字符串数据=MYDATA的=+ HttpUtility.UrlEncode(的Hello World!);
StreamWriter的作家=新的StreamWriter(request.GetRequestStream());
writer.Write(数据);
writer.Close();
HttpWebResponse响应= request.GetResponse()作为HttpWebResponse;
I am making a plugin for Outlook 2010 using VS2010 C#.
The objective of my plugin is to grab the To, CC, BC from the new email when a custom button is pressed from the ribbon and post it to an external url (which takes in a post request). Similar to how forms in html/jsp can post inputs to a different page(url).
So far, I can grab the To,CC,BC and store it in a string variable. But I don't know how to make a post to the external url.
Any help would be greatly appreciated. Thanks.
Here is my code for my function so far:
public void makePost(object Item, ref bool Cancel)
{
Outlook.MailItem myItem = Item as Outlook.MailItem;
if (myItem != null)
{
string emailTo = myItem.To;
string emailCC = myItem.CC;
string emailBCC = myItem.BCC;
if (emailTo == null && emailCC == null && emailBCC == null)
{
MessageBox.Show("There are no recipients to check.");
}
else
{
string emailAdresses = string.Concat(emailTo, "; ", emailCC, "; ", emailBCC);
//do something here to post the string(emailAddresses) to some url.
}
}
}
You need to use WebRequest / HttpWebRequest class, for example:
HttpWebRequest request = HttpWebRequest.Create("http://google.com/postmesmth") as HttpWebRequest;
request.Method = WebRequestMethods.Http.Post;
request.Host = "google.com";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0";
string data = "myData=" + HttpUtility.UrlEncode("Hello World!");
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
这篇关于展望VSTO C#做专为HTML网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!