Creating a mailing list
To create a mailing list, you use the NewslettersManager class. The following code creates a mailing list with the specified Id, Title,DefaultFromName, DefaultReplyToEmail and DefaultSubject through the Native API.
public void CreateMailingList(Guid id, string title, string fromName, string replyToEmail, string subject)
{
NewslettersManager manager = NewslettersManager.GetManager();
MailingList mailingList = manager.GetMailingLists().Where(l => l.Id == id).SingleOrDefault();
if (mailingList == null)
{
mailingList = manager.CreateList(id);
mailingList.Title = title;
mailingList.DefaultFromName = fromName;
mailingList.DefaultReplyToEmail = replyToEmail;
mailingList.DefaultSubject = subject;
manager.SaveChanges();
}
}
First, you initialize the NewslettersManager. Then, you call GetMailingLists to get all mailing lists. Then, you check whether an item with the specified ID exists. Finally, you call the CreateList method, set all properties, and save the changes.