Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read and Delivery Receipts #182

Open
PS2009DT opened this issue Apr 7, 2023 · 5 comments
Open

Read and Delivery Receipts #182

PS2009DT opened this issue Apr 7, 2023 · 5 comments

Comments

@PS2009DT
Copy link

PS2009DT commented Apr 7, 2023

Hi,

It is me again!

Would you be able to add in functionality to add delivery and read notifications. Currently i have modified your code as below but happy for you to devise another approach too.

Using SMTP headers, I check if read or delivery is needed and I set it

internal static Message CreateGraphMessageFromFluentEmail(IFluentEmail email)
{
    var itemBody = new ItemBody
    {
        Content = email.Data.Body,
        ContentType = email.Data.IsHtml ? BodyType.Html : BodyType.Text,
    };

    var message = new Message
    {
        Subject = email.Data.Subject,
        Body = itemBody,
        From = ConvertToRecipient(email.Data.FromAddress),
        ReplyTo = CreateRecipientList(email.Data.ReplyToAddresses),
        ToRecipients = CreateRecipientList(email.Data.ToAddresses),
        CcRecipients = CreateRecipientList(email.Data.CcAddresses),
        BccRecipients = CreateRecipientList(email.Data.BccAddresses),
    };

    SetPriority(email, message);

    //Check if read receipt is needed

    if(email.Data.Headers.ContainsKey("Return-Receipt-To"))
    {
        email.Data.Headers.Remove("Return-Receipt-To");
        email.Data.Headers.Remove("Disposition-Notification-To");
        message.IsDeliveryReceiptRequested = true;
        message.IsReadReceiptRequested = true;
    }

    SetHeaders(email, message);

    return message;
}

Thanks

@DavidDeSloovere
Copy link
Member

We did something similar with tags in an extra library we have on top of FluentEmail.

Where are you using Disposition-Notification-To in your code?
We could have extension methods in the library that set the tags from the application code.

@PS2009DT
Copy link
Author

Not sure what you mean by tags, this is to request a read receipt for the email

@DavidDeSloovere
Copy link
Member

My bad.
We used email.Tags, you are using email.Headers. With same purpose of "configuring" something for the mail sender.

But I think that I understand the Return-Receipt-To header now. MS Graph already knows about that, but IsReadReceiptRequested still needs to be enabled.

Are Disposition-Notification-To and IsDeliveryReceiptRequested also linked?

@PS2009DT
Copy link
Author

The headers can be added to fluent mail object which need to be translated into the flags on ms message object if that makes sense.
From my tests the headers do not work in ms graph and you need to set the relevant flags

@DavidDeSloovere
Copy link
Member

Ok. Headers are removed again. I saw this the first time, but somehow missed it the second time.

Probably need a way to set delivery and read separately. So 2 of these would be needed as extensionmethods

/// <summary>
/// Marks the email to sent with `IsReadReceiptRequested` enabled.
/// </summary>
/// <param name="email">The mail.</param>
/// <returns>Instance of the Email class.</returns>
public static IFluentEmail EnableReadReceipt(this IFluentEmail email)
{
  return email.Tag(Graph_EnableReadReceipt);
}

And then the send checks the Tag list for these markers. The way you used headers.

Do you have time to submit a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants