1

Visual Studio 2010 を使用して asp.net C# でプロジェクトを作成しています。ユーザーがボタンをクリックすると Outlook ウィンドウを開いて電子メールを送信する関数を作成したいと考えています。

私はこれを試しました:

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Application oApp    = new Outlook.Application ();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem ( Outlook.OlItemType.olMailItem );
oMailItem.To    = address;
// body, bcc etc...
oMailItem.Display ( true );

しかし、コンパイラは、名前空間 Microsoft 内に名前空間 Office がないと言っています。実際、私のコンピューターには Outlook を含む Microsoft Office が完全にインストールされています。

Office ライブラリを Visual Studio に含める必要がありますか? 問題はどのように解決できますか?

4

3 に答える 3

3

これは Outlook を使用して、受信者、件名、および本文がプリロードされた電子メールを送信します。

<A HREF="mailto:recipient@domain.com?subject=this is the subject&body=Hi, This is the message body">send outlook email</A>
于 2012-12-11T22:10:22.490 に答える
1

を使用する場合はMicrosoft.Office.Interop.Outlook、Outlook がサーバーにインストールされている必要があります (ユーザーのコンピューターではなく、サーバー上で実行されます)。

SmtpClientを使用してみましたか?

 System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
        using (m)
        {
            //sender is set in web.config:   <smtp from="my alias &lt;mymail@mysite.com&gt;">
            m.To.Add(to);
            if (!string.IsNullOrEmpty(cc))
                m.CC.Add(cc);
            m.Subject = subject;
            m.Body = body;
            m.IsBodyHtml = isBodyHtml;
            if (!string.IsNullOrEmpty(attachmentName))
                m.Attachments.Add(new System.Net.Mail.Attachment(attachmentFile, attachmentName));

            System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            try
            { client.Send(m); }
            catch (System.Net.Mail.SmtpException) {/*errors can happen*/ }
        }
于 2012-07-31T09:07:24.247 に答える
1

むしろ、このように試して、Microsoft.Office.Interop.Outlook; を使用して追加します。参照

        Application app = new Application();
        NameSpace ns = app.GetNamespace("mapi");
        ns.Logon("Email-Id", "Password", false, true);
        MailItem message = (MailItem)app.CreateItem(OlItemType.olMailItem);
        message.To = "To-Email_ID";
        message.Subject = "A simple test message";
        message.Body = "This is a test. It should work";

        message.Attachments.Add(@"File_Path", Type.Missing, Type.Missing, Type.Missing);

        message.Send();
        ns.Logoff();
于 2013-03-11T04:29:47.923 に答える