简体   繁体   English

使用C#从Outlook Express发送电子邮件

[英]Send email from Outlook Express in C#

How do I open Outlook Express in C# 2008? 如何在C#2008中打开Outlook Express?

How to attach a file from my application to Outlook? 如何将文件从我的应用程序附加到Outlook?

Outlook Express has been obsolete for so long I can't even remember the last time I actually saw anyone using it... It's a security nightmare, and has been removed from Windows ages ago Outlook Express已经过时了很长时间我甚至不记得上次我真正看到有人使用它...这是一个安全噩梦,并且已经从Windows很久以前删除了

AFAIK, Outlook Express doesn't have an API to manipulate it programmatically (but Outlook does). AFAIK,Outlook Express没有用于以编程方式操作它的API(但Outlook确实如此)。 As others have suggested in comments, you should probably send the mail directly from your C# code, without involving Outlook Express. 正如其他人在评论中建议的那样,您应该直接从C#代码发送邮件,而不涉及Outlook Express。 Check out the System.Net.Mail namespace in MSDN, it contains everything you might need (including code samples) 查看MSDN中的System.Net.Mail命名空间,它包含您可能需要的所有内容(包括代码示例)

As others have pointed out you better use the System.Net.Mail if you simply want to send a mail. 正如其他人指出的那样,如果您只想发送邮件,最好使用System.Net.Mail。

If for whatever reason you want to send mails using Outlook you'll have to use Office interop. 如果由于某种原因你想使用Outlook发送邮件,你将不得不使用Office互操作。
Something like this: 像这样的东西:

 using Outlook = Microsoft.Office.Interop.Outlook;

    Outlook.Application oApp = new Outlook.Application();

                        Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
                        email.Recipients.Add("someEmailAddress@dom.com");
                        email.Subject = "Subject";
                        email.Body = "Message";


                        ((Outlook.MailItem)email).Send();

If you are looking to compose an email using the user's default e-mail client, try this: 如果您要使用用户的默认电子邮件客户端撰写电子邮件,请尝试以下操作:

using System;
using System.Diagnostics;

namespace RunMailTo
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("mailto://name@example.com");
        }
    }
}

You can add additional parameters to the mailto: URL to set the subject, body, etc. See http://msdn.microsoft.com/en-us/library/aa767737%28VS.85%29.aspx for more information. 您可以向mailto:URL添加其他参数以设置主题,正文等。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/aa767737%28VS.85%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM