Send mail using default webclient in ASP.NET using MAPI in C# web application

醉酒当歌 提交于 2021-02-20 04:50:29

问题


I am using MAPI for opening default web mail client in my C# web application. Now it is opening as dialog box first then outlook window. I want to open direct default mail client window using MAPI.

But when I am deploying on IIS then MAPI is not calling Mail Dialog box.

Is there simple way of calling web mail client using MAPI with attachment?


回答1:


Don't use the MAPI. Use System.Net.Mail: http://www.systemnetmail.com/faq/3.4.1.aspx

static void AttachmentFromFile()
{
    //create the mail message
    MailMessage mail = new MailMessage();

    //set the addresses
    mail.From = new MailAddress("me@mycompany.com");
    mail.To.Add("you@yourcompany.com");

    //set the content
    mail.Subject = "This is an email";
    mail.Body = "this content is in the body";

    //add an attachment from the filesystem
    mail.Attachments.Add(new Attachment("c:\\temp\\example.txt"));

    //to add additional attachments, simply call .Add(...) again
    mail.Attachments.Add(new Attachment("c:\\temp\\example2.txt"));
    mail.Attachments.Add(new Attachment("c:\\temp\\example3.txt"));

    //send the message
    SmtpClient smtp = new SmtpClient("127.0.0.1");
    smtp.Send(mail);

}



回答2:


Do you want to do that on the client of the server side? I doubt you will want any window to be displayed on the server when running in a service (IIS) where noone will dismiss these windows. If you want to run on the client side, mailto: url is pretty much your only choice.



来源:https://stackoverflow.com/questions/12234916/send-mail-using-default-webclient-in-asp-net-using-mapi-in-c-sharp-web-applicati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!