How to Open outlook at client end in asp.net mvc

Vinit Kumar 21 Reputation points
2022-05-16T04:22:36.99+00:00

How to Open outlook at client end in asp.net mvc

My code is below but its not working after publishing

        try
        {
            List<string> lstAllRecipients = new List<string>();
            //Admin email id

            lstAllRecipients.Add(ConfigurationManager.AppSettings["SenderEmail"].ToString());


            Outlook.Application outlookApp = new Outlook.Application();
            Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            Outlook.Inspector oInspector = oMailItem.GetInspector;


            // Recipient
            Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
            foreach (String recipient in lstAllRecipients)
            {
                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
                oRecip.Resolve();
            }

            //Add CC
            string pcoEmail = objregister.getPCOEmail(Id);
            Outlook.Recipient oCCRecip = oRecips.Add(pcoEmail);
            oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
            oCCRecip.Resolve();

            //Add Subject
            oMailItem.Subject = "Mail from PCO Regarding - " + Id;

            // body, bcc etc...

            //Display the mailbox
            oMailItem.Display(true);
        }
        catch (Exception objEx)
        {
            Response.Write(objEx.ToString());
        }
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,666 Reputation points
    2022-05-16T04:52:49.143+00:00

    In ASP.Net MVC, your code will be executing in the server side, it will never be executed in the client machine. If you are using Exchange online / Microsoft 365, you may use graph API to send email.

    https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.