none
create an email bttuon on a webapp, so upon click, it emails by attaching the report via outlook RRS feed

  • Question

  • Can anyone assist me on this:

    So I added an email button tto our web app and all I need it to do is to send an email via outlook by attaching the report.

    But it seems not still working. Can anyone have a look at my code below and let me know if there is anything i am not doing ..right

    using Outlook = Microsoft.Office.Interop.Outlook;

    private void button_Click(object sender, System.EventArgs e)
            {
                    // Create the Outlook application.
                    Outlook.Application oApp = new Outlook.Application();
                    // Create a new mail item.
                    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                    // Set HTMLBody.
                    //add the body of the email
                    oMsg.HTMLBody = "Body";
                    //Add an attachment.
                    string sDisplayName = "MyAttachment";
                    int iPosition = oMsg.Body.Length + 1;
                    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                    //now attached the file
                    Outlook.Attachment oAttach = oMsg.Attachments.Add
                                                 (@"/***/*** ", iAttachType, iPosition, sDisplayName);
                    //Subject line
                    oMsg.Subject = "Your Subject will go here.";
                    // Add a recipient.
                    Outlook.Recipients oRecips = oMsg.Recipients;
                    // Change the recipient as you want.
                    Outlook.Recipient oRecip = oRecips.Add("abad@gmail.com");
                    oRecip.Resolve();
                    // Send.
                    oMsg.Send();
                    // Clean up.
                    oRecip = null;
                    oRecips = null;
                    oMsg = null;
                    oApp = null;
      
                }


    AbaDougan

    Monday, October 14, 2019 10:52 PM