none
How to send an alert reminder with an email using C# code RRS feed

  • Question

  • Hi

    I am trying to send an alert reminder with the email that my application is sending,

    I am adding the reminder to the email header at this line:

    email.Headers.Add("Follow-up-by", string.Format("{0: dd MM yyyy HH:mm:ss zz}", ReplyDate));

    I am getting the email but no reminder alert on the header. any idea what am I doing wrong?

    Thank you!


    public void Send(string recipientEmail, string emailBody, string emailSubject)
        {
            MailMessage email = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(_settings.EmailServer);
    
            DateTime ReplyDate = DateTime.Now.AddDays(5);
            //email.Headers.Add("X-Message-Flag", "Follow up");
            email.Headers.Add("Follow-up-by", string.Format("{0: dd MM yyyy HH:mm:ss zz}", ReplyDate));  
    
            email.From = new MailAddress(_settings.SenderEmail);
    
            if (!string.IsNullOrEmpty(_settings.TestingEmail))
            {
               email.To.Add(_settings.TestingEmail);
            }
            else
            {
                email.To.Add(recipientEmail);
            }
    
            email.Subject = emailSubject;
    
            email.IsBodyHtml = true;
            email.Body = emailBody;
    
            smtpServer.Send(email);
        }
    }


    I am getting the email but no reminder on the header.

    Thank you!

    Saturday, September 8, 2018 8:15 PM

All replies

  • Sunday, September 9, 2018 1:08 AM
  • Thank you very much, it worked like a charm :) 
    Monday, September 10, 2018 12:43 PM
  • I think I spoke too early :(, the above made the Follow up by <Date> show on the email header but the reminder popup is not coming. any idea how to make the reminder popup for the time assigned to follow up? your help is much appreciated.

    Monday, September 10, 2018 1:49 PM
  • Hi Naz777,

    If your machine install outlook, please refer to the following link and code, which use office.interop.

    https://stackoverflow.com/questions/44551860/net-how-can-i-send-an-email-message-where-it-will-popup-upon-receipt-without-ha

        Microsoft.Office.Interop.Outlook.MailItem objMailItem;
        objMailItem.FlagStatus = Microsoft.Office.Interop.Outlook.OlFlagStatus.olFlagMarked;
        objMailItem.FlagDueBy = BackDate;
        objMailItem.FlagIcon = Microsoft.Office.Interop.Outlook.OlFlagIcon.olRedFlagIcon;
        objMailItem.FlagRequest = "Follow Up";
        objMailItem.ReminderSet = true;
        objMailItem.ReminderPlaySound = true;
    
    

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 11, 2018 7:17 AM
    Moderator
  • Thank you Zhanglong, I have implemented what you have suggested but I am getting the below error:

    Retrieving the COM class factory for component with CLSID {00061033-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

    so this what did:

    installed Microsoft.Office.Interop.Outlook.15.0.4797.1003 and it was added to the reference.

    and the below is my code the error is throwing at Microsoft.Office.Interop.Outlook.MailItem objMailItem = new Microsoft.Office.Interop.Outlook.MailItem(); line and even if this works how would I add this object to the MailMessage?:

    public void Send(string recipientEmail, string emailBody, string emailSubject)
            {
                MailMessage email = new MailMessage();
                SmtpClient smtpServer = new SmtpClient(_settings.EmailServer);


                var culture = new CultureInfo("en-US");
                var replyBy = DateTime.UtcNow.AddMinutes(4).ToString(@"ddd, dd MMM yyyy HH:mm:ss \G\M\T", culture);
                email.Headers.Add("X-Message-Flag", "Follow up");           
                email.Headers.Add("Reply-By", replyBy);

                Microsoft.Office.Interop.Outlook.MailItem objMailItem = new Microsoft.Office.Interop.Outlook.MailItem();

                objMailItem.FlagStatus = Microsoft.Office.Interop.Outlook.OlFlagStatus.olFlagMarked;
                objMailItem.FlagDueBy = DateTime.UtcNow.AddMinutes(4);
                objMailItem.FlagIcon = Microsoft.Office.Interop.Outlook.OlFlagIcon.olRedFlagIcon;
                objMailItem.FlagRequest = "Follow Up";
                objMailItem.ReminderSet = true;
                objMailItem.ReminderPlaySound = true;

                email.From = new MailAddress(_settings.SenderEmail);

                if (!string.IsNullOrEmpty(_settings.TestingEmail))
                {
                   email.To.Add(_settings.TestingEmail);
                }
                else
                {
                    email.To.Add(recipientEmail);
                }

                email.Subject = emailSubject;

                email.IsBodyHtml = true;
                email.Body = emailBody;

                smtpServer.Send(email);
            }

    Wednesday, September 12, 2018 5:09 PM
  • Hi Naz777,

    Please check if you have installed Microsoft Office Outlook in your machine. The interop assembly is just a .NET wrapper for COM component of Outlook. This component should be registered for interop to work. 

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 18, 2018 1:00 AM
    Moderator
  • I am using MS O365 Outlook, does this mean that any recipient needs to install MS office on their machine?
    Tuesday, September 18, 2018 1:00 PM
  • Hi Naz,

    Yes, You can't use Microsoft.Office.Interop without having ms office installed.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 19, 2018 1:41 AM
    Moderator