【问题标题】:Outlook VSTO C# Make post to html urlOutlook VSTO C# 发布到 html url
【发布时间】:2013-07-10 19:27:33
【问题描述】:

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

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

到目前为止,我可以获取 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.
        }
    }
}

【问题讨论】:

    标签: c# post plugins vsto outlook-2010


    【解决方案1】:

    你需要使用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;
    

    【讨论】:

    • 非常感谢!我明白了。但我正在处理一个问题。我在“字符串数据 = HttpUtility.UrlEncode(emailAdresses);”行中遇到错误它说 HttPUtility 在当前上下文中不存在。我做了很多导入,包括:使用 System.Net;使用 System.Web;仍然没有运气。谢谢
    • 您需要添加对 System.Web.dll 的引用或使用: Uri.EscapeUriString("Hello World!");而是
    • 谢谢。 Uri.EscapeUriString 工作。现在我在行出现异常错误:'HttpWebResponse response = request.GetResponse() as HttpWebResponse;'调试器显示响应正在获取空值。可能与我发布它的 html 页面有关。谢谢。
    猜你喜欢
    • 2019-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2019-02-12
    • 2018-03-10
    • 1970-01-01
    • 2023-03-17
    相关资源
    最近更新 更多