【问题标题】:How to send E-mail with voting options using outlook in c#如何在 c# 中使用 Outlook 发送带有投票选项的电子邮件
【发布时间】:2020-08-28 00:44:45
【问题描述】:

我尝试通过 c# 中的 Outlook 发送是或否问题。我想解释一下我想要什么。

1- 发送一封电子邮件,邮件必须包含是或否按钮,当接收者投票是或否时,我必须收集他/她的答案并在我的数据库中更新状态。我知道如何更新我的数据库中的状态,只是我想知道如何使用 c# 通过 Outlook 发送是或否问题。对不起我的英语。

Outlook._Application _app = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = "abc@xyz.com";
mail.Subject = "this is subject";
mail.Body = "this is body";
mail.Importance = Outlook.OlImportance.olImportanceNormal;
((Outlook.MailItem)mail).Send();
MessageBox.Show("your mail sent");

此代码可以正常发送和发送电子邮件,但我不知道如何在我的邮件中添加是或否按钮。

【问题讨论】:

  • YES/NO 功能是 Outlook 的内置功能吗?如果没有,您必须创建一个指向您提供的服务器的链接。
  • 您使用哪个平台? windows 窗体、mvc 或 asp.net
  • 我相信mail.Body 接受html?如果是这样,您可以使用 button 标签创建简单的按钮并添加 js 以将他们的投票发送到远程服务器
  • 是的,这个问题不是重复的。您可以尝试制作一个包含“是”或“否”按钮的 HTML 正文,该按钮将输出发送到远程服务器。 <button onClick="sendToServer("YES");">Yes</button> <button onClick="sendToServer("NO");">No</button>你需要根据自己的需要写服务器。

标签: c# vba outlook


【解决方案1】:

第一步

创建一个包含“是”“否”按钮的有效 HTML 正文

我必须从一开始就这么说,我没有任何关于 Outlook 版本的信息,但我可以通过 Gmail SMTP 给你;

        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

        mail.From = new MailAddress("TestBlahBlah@gmail.com");
        mail.To.Add("your_mail_adress@gmail.com");
        mail.Subject = "Test Mail";
        mail.IsBodyHtml = true;     // <-- This here is improtant
        mail.Body = "Vote for x y z<br/> <button>YES</button> <button>NO</button>";
        SmtpServer.UseDefaultCredentials = false;
        SmtpServer.Port = 587;
        SmtpServer.Credentials = new System.Net.NetworkCredential("TestBlahBlah@gmail.com", "your_l0ng&pRobably_SeCuRe_pwd_157");
        SmtpServer.EnableSsl = true;// <-- This is also important

        SmtpServer.Send(mail);

第 2 步

我不懂 javascript,所以我无能为力,但你需要做的是:

创建服务器

制作一个在 node.js 上运行的服务器,或者您也可以使用 c# 使用套接字等来完成。

通过您的按钮向该服务器发送信息

mail.Body = "<script>  var someNiceVar = goodString'; </script>"+
            "<script> function sendData(Server server, Data data) {sendDataToServer("YES")} </script>"+
            " Vote for yourQuestionOrSomething "
            " <button onClick="sendData(Server, 'YES')">YES</button>"+
            " <button onClick="sendData(Server, 'NO')">NO</button>"+
            " "

免责声明:这不是真正的代码:)

第三步

记录您从邮件中收到的数据。

重要提示

关于 gmail 版本的一件非常重要的事情是,gmail 不会默认启用此功能,因此要使用第三方应用程序从您的帐户向其他帐户发送邮件,您需要启用信任度较低的应用程序

Manage your google account &gt; Security &gt; Less Secure App Access &gt; Trust less secure apps &gt; On

同样,我不知道这个的 Outlook 版本,但我会小心的。

【讨论】:

    【解决方案2】:

    您可以使用MailItem.VotingOptions 属性来设置投票选项。要阅读您需要使用MailItem.VotingResponse 属性的响应。此属性通常设置为由VotingOptions 属性在回复原始消息时返回的分隔值之一。例如:

        using Outlook = Microsoft.Office.Interop.Outlook;
    
        private void OrderPizza()
        {
            Outlook.MailItem mail = (Outlook.MailItem)Application.CreateItem(
                Outlook.OlItemType.olMailItem);
    
            mail.VotingOptions = “Cheese; Mushroom; Sausage; Combo; Veg Combo;”
    
            mail.Subject = “Pizza Order”;
            mail.Display(false);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多