Table of Contents

Class Ecommerce.Cart.SendingConfirmationMailArgs

Namespace
Dynamicweb.Ecommerce.Notifications
Assembly
Dynamicweb.Ecommerce.dll

Provides information about order and confirmation mail just before each individual Order Email is sent.

public class Ecommerce.Cart.SendingConfirmationMailArgs : NotificationArgs
Inheritance
Ecommerce.Cart.SendingConfirmationMailArgs
Inherited Members

Examples

using System.IO;
using System.Net.Mail;
using Dynamicweb.Core;
using Dynamicweb.Imaging;

namespace Dynamicweb.Ecommerce.Examples.Notifications;

[Dynamicweb.Extensibility.Notifications.Subscribe(Ecommerce.Notifications.Ecommerce.Cart.SendingConfirmationMail)]
public class EcomCartSendingConfirmationMailObserver : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
{
    public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
    {
        var sendingConfirmationMailArgs = args as Ecommerce.Notifications.Ecommerce.Cart.SendingConfirmationMailArgs;
        if (sendingConfirmationMailArgs is null)
            return;

        //**** Example for creating a PDF attachment for the order emails **** //

        //EXAMPLE with a razor template
        //Load a template - with full html, including html, body, inline css etc. IE browser compatible
        var htmlForPdfTemplate = new Rendering.Template("/eCom7/CartV2/Mail/pdfReceipt.cshtml");

        //Create an order renderer instance
        var orderRenderer = new Frontend.Renderer();
        //Render all order tags
        orderRenderer.RenderOrder(sendingConfirmationMailArgs.Order, htmlForPdfTemplate);

        //Add custom tags to the template
        htmlForPdfTemplate.SetTag("RecipientEmail", sendingConfirmationMailArgs.Recipient.Address);
        htmlForPdfTemplate.SetTag("ReceiptSubject", sendingConfirmationMailArgs.MailMessage.Subject);

        string html = htmlForPdfTemplate.Output();

        //Create a pdf from the template
        string pathToOrderConfirmation = SystemInformation.MapPath($"/Files/System/OrderExport/Order{sendingConfirmationMailArgs.Order.Id}.pdf");

        var settings = new PdfRendererSettings
        {
            PaperSizeCustomWidth = 300,
            PaperSizeCustomHeight = 750
        };
        var renderer = new PdfRenderer(settings);
        byte[] data = renderer.RenderFromHtml(html);
        File.WriteAllBytes(pathToOrderConfirmation, data);

        //Attach the pdf to the email
        sendingConfirmationMailArgs.MailMessage.Attachments.Add(new Attachment(pathToOrderConfirmation));
    }
}

Remarks

The passed NotificationArgs is Ecommerce.Cart.SendingConfirmationMailArgs

Constructors

SendingConfirmationMailArgs(MailMessage, MailAddress, Order, ModuleSettings)

Initializes a new instance of the Ecommerce.Cart.SendingConfirmationMailArgs class.

public SendingConfirmationMailArgs(MailMessage mailMessage, MailAddress recipient, Order order, ModuleSettings cartModuleSettings)

Parameters

mailMessage MailMessage

The mail message.

recipient MailAddress

The recipient.

order Order

The order.

cartModuleSettings ModuleSettings

The module settings.

Properties

CartModuleSettings

Gets the module settings.

public ModuleSettings CartModuleSettings { get; }

Property Value

ModuleSettings

The module settings.

MailMessage

Gets the mail message.

public MailMessage MailMessage { get; }

Property Value

MailMessage

The mail message.

Order

Gets the order.

public Order Order { get; }

Property Value

Order

The order.

Recipient

Gets the recipient.

public MailAddress Recipient { get; }

Property Value

MailAddress

The recipient.

SkipThisMail

Gets or sets a value indicating whether to skip the current email, preventing it from being sent.

public bool SkipThisMail { get; set; }

Property Value

bool

true if the mail is skipped; otherwise, false.

StopSendingMoreMails

Gets or sets a value indicating whether to skip the current email and all subsequent emails from being sent.

public bool StopSendingMoreMails { get; set; }

Property Value

bool

true if no more mails should be sent; otherwise, false.

See Also

To top