1

我正在使用 VS2010 C# 为 Outlook 2010 制作插件。

我的插件的目的是在从功能区按下自定义按钮时从新电子邮件中获取 To、CC、BC 并将其发布到外部 url(接收发布请求)。类似于 html/jsp 中的表单如何将输入发布到不同的页面(url)。

到目前为止,我可以获取 To、CC、BC 并将其存储在字符串变量中。但我不知道如何向外部网址发帖。

任何帮助将不胜感激。谢谢。

到目前为止,这是我的函数代码:

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.
        }
    }
}
4

1 回答 1

2

您需要使用WebRequest / HttpWebRequest类,例如:

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;
于 2013-07-10T21:41:18.703 回答