Using the Email Manager API

    The Magentrix platform allows you to send emails with Magentrix EmailManager. EmailManager uses the STMP settings provided in the Company Preferences in order to send outbound emails. Examples.

     

    Methods

    NameArgumentsReturn TypeDescription

    CreateEmail

    (static method)

    string templateId,
    object model,
    Dictionary<string,object> dataBag
    MailMessageConstructs a single outbound email object from the template specified, which can be further customized before sending out.
    Model and dataBag objects are used for serving the merge fields within the template Subject and Body.
    dataBag argument is optional

    CreateEmail

    (static method)

    EmailTemplate template,
    object model,
    Dictionary<string,object> dataBag
    MailMessageConstructs a single outbound email object from the template specified, which can be further customized before sending out.
    Model and dataBag objects are used for serving the merge fields within the template Subject and Body.
    dataBag argument is optional
    CreateAttachmentstring name,
    Stream fileStream
    AttachmentConstructs an attachment from a Stream, which can be added to the outbound MailMessage.
    CreateAttachmentstring name,
    byte[] fileBytes
    AttachmentConstructs an attachment from an array of bytes, which can be added to the outbound MailMessage.
    CreateAttachmentstring documentIdAttachmentConstructs an attachment from a Document, which can be added to the outbound MailMessage.
    The document type cannot be a YouTube/Vimeo Video or Link.
    AttachFileMailMessage message,
    string name,
    Stream fileStream
    voidConstructs and adds an attachment from a Stream to the outbound MailMessage.
    AttachFileMailMessage message,
    string name,
    byte[] fileBytes
    voidConstructs and adds an attachment from an array of bytes to the outbound MailMessage.
    AttachFileMailMessage message,
    string documentId
    voidConstructs and adds an attachment from a Document to the outbound MailMessage.
    ​The document type cannot be a YouTube/Vimeo Video or Link.
     
    SendEmailMailMessage messagevoidSends an outbound email using the MailMessage.
    SendEmailstring to,
    string subject,
    string message
    voidSends an outbound email to the email address provided.
    SendEmailsList<MailMessage>voidSends one or more outbound emails using the list of MailMessages.

     


    When using the EmailManager, enclose it in a using statement. 

    using (EmailManager mailManager = new EmailManager())
    {
       // your code here
    }
    

     

    Examples

    Example of sending an email to a Contact:

    var contact = Database.Query<Contact>().Where(a=>a.Name == "John Smith").First();
    using(EmailManager mailManager = new EmailManager())
    {
       //Create an email message using an existing email template,
       // pass the ID of the email template.
       var message = EmailManager.CreateEmail("7OH00000000001N00a2", contact);
       
       //add at least one recepient to the To list or CC or BCC
       message.To.Add(new System.Net.Mail.MailAddress(contact.Email, contact.Name));
    
       //send the email message
       mailManager.SendEmail(message);
    }

     

    Example of sending an email to the current user with an attachment:

    var emailTemplate = Database.Query<EmailTemplate>().Where(a=>a.Name == "New Price List Alert").First();
    var user = SystemInfo.UserInfo;
    
    //locate the Document to attach.
    var doc = Database.Query<Document>().Where(a=>a.Name == "2014 Price List.pdf").First();
    
    //send the email
    using(EmailManager sender = new EmailManager())
    {
        var message = EmailManager.CreateEmail(emailTemplate, user);
        message.To.Add(new System.Net.Mail.MailAddress(user.Email,user.Name));
        EmailManager.AttachFile(message, doc.Id);
        sender.SendEmail(message);
    }
    

     

    « Previous ArticleNext Article »

     0.0 (0)


    Comments

    No records to display

    Your Comment:

    Email address is not displayed with comment.

    About the Author
    Tags