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
Name | Arguments | Return Type | Description |
---|
CreateEmail (static method) | string templateId,
object model,
Dictionary<string,object> dataBag | MailMessage | Constructs 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 | MailMessage | Constructs 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 |
CreateAttachment | string name, Stream fileStream | Attachment | Constructs an attachment from a Stream, which can be added to the outbound MailMessage. |
CreateAttachment | string name, byte[] fileBytes | Attachment | Constructs an attachment from an array of bytes, which can be added to the outbound MailMessage. |
CreateAttachment | string documentId | Attachment | Constructs an attachment from a Document, which can be added to the outbound MailMessage.
The document type cannot be a YouTube/Vimeo Video or Link. |
AttachFile | MailMessage message, string name, Stream fileStream | void | Constructs and adds an attachment from a Stream to the outbound MailMessage. |
AttachFile | MailMessage message, string name, byte[] fileBytes | void | Constructs and adds an attachment from an array of bytes to the outbound MailMessage. |
AttachFile | MailMessage message, string documentId | void | Constructs and adds an attachment from a Document to the outbound MailMessage.
The document type cannot be a YouTube/Vimeo Video or Link.
|
SendEmail | MailMessage message | void | Sends an outbound email using the MailMessage. |
SendEmail | string to,
string subject,
string message | void | Sends an outbound email to the email address provided. |
SendEmails | List<MailMessage> | void | Sends 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
}
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);
}