【发布时间】:2015-10-09 14:40:48
【问题描述】:
在我的 Class1 oMsg.HTMLBody 中,我想提供一个参考,以便在单击发送的电子邮件中的链接时调用 DBConnectivity.cs 类的连接()方法。你能帮忙吗?
Class1.cs
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Data.SqlClient;
namespace Outlook_SendMailItem
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application by using inline initialization.
Outlook.Application oApp = new Outlook.Application();
//Create the new message by using the simplest approach.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
//Add a recipient.
// TODO: Change the following recipient where appropriate.
Outlook.Recipient oRecip = (Outlook.Recipient)oMsg.Recipients.Add("aman.agarwal4@cognizant.com");
oRecip.Resolve();
//Set the basic properties.
oMsg.Subject = "This is the subject of the test message";
oMsg.HTMLBody = "<a href=\"what_is_required_here\">Approve</a><pre> </pre><a href=\"what_is_required_here\">Reject</a>";
// Add an attachment.
// TODO: change file path where appropriate
String sSource = "C:\\Users\\461023\\Desktop\\Servlets.txt";
String sDisplayName = "MyFirstAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMsg.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
// If you want to, display the message.
// oMsg.Display(true); //modal
//Send the message.
oMsg.Save();
((Outlook._MailItem)oMsg).Send();
//Explicitly release objects.
oRecip = null;
oAttach = null;
oMsg = null;
oApp = null;
}
// Simple error handler.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught: ", e);
}
//Default return value.
return 0;
}
}
}
DBConnectivity.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace SendEmail
{
class DBConnectivity
{
public void connectivity()
{
string query = "Update Leaves Set status = @status where emailid = @emailid";
using (SqlConnection connection = new SqlConnection("Data Source = ; Initial Catalog = ; Integrated Security = SSPI"))
using (SqlCommand cmd = new SqlCommand(query , connection))
{
connection.Open();
cmd.Parameters.AddWithValue("status", "approved");
cmd.Parameters.AddWithValue("emailid", "email_id");
int affected_rows = cmd.ExecuteNonQuery();
}
}
}
}
【问题讨论】:
-
我认为没有办法做到这一点。我会创建一个 php 脚本并将其上传到网上,并在用户点击批准/拒绝时将用户重定向到此页面。
-
你能告诉我怎么做吗?
-
类似
oMsg.HTMLBody = "<a href=\"http:\\yourpage.com?accepted=1\">Approve</a><pre> </pre><a href=\"http:\\yourpage.com?accepted=0\">Reject</a>";的东西在线搜索php脚本,用php执行sql命令相当容易