C#: How to save email reply on sql

ika palad 86 Reputation points
2022-02-03T00:13:10.797+00:00

Hello Community,

I'm trying to create an email reply on Outlook and save the email details (Sender, To, CC, Subject, Body and Attachment) on Sql Server. Can you please guide me. Thank you!

More Details: After receiving an email the user will reply to an email after replying the user data (Sender, To, CC, Subject, Body and Attachment) will save on sql

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,401 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,311 Reputation points Microsoft Vendor
    2022-02-03T07:16:32.977+00:00

    @ika palad , you could try the following code to use c# to reply an email.

    private void button1_Click(object sender, EventArgs e)  
            {  
                Outlook.Application app =new  Outlook.Application();  
                Outlook.MailItemClass emi = (Outlook.MailItemClass)replyMail;  
                emi.ItemEvents_10_Event_Reply += Emi_ItemEvents_10_Event_Reply;  
                emi.ItemEvents_Event_Reply += Emi_ItemEvents_Event_Reply;  
      
                MessageBox.Show("success");  
            }  
      
            private void Emi_ItemEvents_Event_Reply(object Response, ref bool Cancel)  
            {  
                Outlook.MailItem mail = Response as Outlook.MailItem;  
                Console.WriteLine(mail.Body);  
                Console.WriteLine(mail.Subject);  
                Console.WriteLine(mail.Sender);  
                Console.WriteLine(mail.To);  
                Console.WriteLine(mail.CC);  
                Console.WriteLine(mail.Attachments.Count);  
      
            }  
    

    Please note that we need to use MailItemClass.ItemEvents_Event_Reply Event.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.