如何在c#中使用Outlook发送带有投票选项的电子邮件

问题描述 投票:0回答:1

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

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

Outlook._Application _app = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = "[email protected]";
mail.Subject = "this is subject";
mail.Body = "this is body";
mail.Importance = Outlook.OlImportance.olImportanceNormal;
((Outlook.MailItem)mail).Send();
MessageBox.Show("your mail sent");

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

c# outlook outlook-vba
1个回答
0
投票

步骤1

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

我从一开始就必须说这一点,但是我没有有关Outlook版本的任何信息,但是我可以给您Gmail SMTP的信息;

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

        mail.From = new MailAddress("[email protected]");
        mail.To.Add("[email protected]");
        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("[email protected]", "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>"+
            " "

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

步骤3

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

重要提示

关于gmail版本非常重要的一点是gmail不允许默认设置,因此要使用第三方应用程序将邮件从您的帐户发送到其他帐户,您需要启用信任度较低的应用程序,从

Manage your google account > Security > Less Secure App Access > Trust less secure apps > On

同样,我不知道它的前景版本,但是我会小心。

© www.soinside.com 2019 - 2024. All rights reserved.