The following sample code shows how you can create a new message, edit its text and finally delete it, all using the API.
[C#]
using CMS.Messaging; using CMS.CMSHelper; using CMS.SiteProvider; using CMS.GlobalHelper;
...
// Creates a new message from CurrentUser to administrator MessageInfo message = new MessageInfo(); message.MessageSubject = "Subject"; message.MessageBody = "Hello world!"; message.MessageSenderUserID = CMSContext.CurrentUser.UserID; message.MessageRecipientUserID = UserInfoProvider.GetUserInfo("administrator").UserID; message.MessageSent = DateTime.Now; MessageInfoProvider.SetMessageInfo(message);
// Gets the previously created message and edits its body MessageInfo messageToEdit = MessageInfoProvider.GetMessageInfo(message.MessageID); messageToEdit.MessageBody += " This message was edited"; MessageInfoProvider.SetMessageInfo(messageToEdit);
// Deletes the previously created and edited message MessageInfoProvider.DeleteMessageInfo(message.MessageID); |
Page url: http://devnet.kentico.com/docs/devguide/index.html?creating_a_new_message.htm