我一直在按照以下示例使用C#代码成功发送电子邮件: MSDN Mail Message
但是,我希望代码能够在用户计算机上显示撰写的电子邮件消息,以便用户在点击Outlook上的发送按钮之前可以进行最终检查。
在VBA世界中,我可以使用mail.Display代替mail.Send。 任何人都可以提供一些建议来实现C#中的建议吗?
感谢。
答案 0 :(得分:1)
这个怎么样......
private void btnEmail_Click(object sender, EventArgs e)
{
string command = "mailto:somebody@domain.com?subject=The Subject&bcc=another@codegaim.com&body=Hi,I found this website and thought you might like it http://www.geocities.com/wowhtml/";
Process.Start(command);
}
答案 1 :(得分:0)
为我的问题找到了一个很好的解决方案,即使用Microsoft Office Interop Outlook而不是System.Net.MailMessage
紧随其后: How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address
//using Microsoft.Office.Interop.Outlook;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Outlook;
namespace ConsoleApplication1
{
using Outlook = Microsoft.Office.Interop.Outlook;
public static class Program
{
static void Main(string[] args)
{
SendUsingAccountExample();
}
private static void SendUsingAccountExample()
{
var application = new Application();
var mail = (_MailItem)application.CreateItem(OlItemType.olMailItem);
mail.Body = "Hello";
mail.Subject = "Good Bye";
mail.To = "hello@google.com";
// Next 2 lines are optional. if not specified, the default account will be used
Outlook.Account account = Application.Session.Accounts["MyOtherAccount"];
mail.SendUsingAccount = account;
mail.Display(false); // To Display
//mail.Send(); // To Send
}
}
}