Mono Support How can I send a private message programmatically? (Closed)

Viewed 24463 time(s), 3 post(s), 7/20/2011 2:36:33 PM - by inanc
7/20/2011 2:36:33 PM
469 Reputation 60 Total posts

Hello,
How can I send a private message programmatically? Can you give an example please?

I am trying to use the method

public virtual bool SendMessageToUser(
Guid messageId,
Guid userId,
MessageStatus status,
bool sendMailCopy
)

But no use.
Thank you.
Inanc

1
7/20/2011 3:05:40 PM
7207 Reputation 956 Total posts

Hi Inanc,
Message sending is actually a two step process if you are going to use the MessageRepository: first you need to create and store the actual message, and after that you are going to use the method you discovered to pass the message to the intended recipients.
The code would look like this:

var messageRep = MonoSoftware.MonoX.Repositories.MessageRepository.GetInstance();
Guid messageId = GuidExtension.NewSequentialGuid();
//create and store the message
SnMessageEntity message = messageRep.SaveMessage(SecurityUtility.GetUserId(), messageId, "Hello message", "Message text body", Guid.Empty, UserName);
//pass the message to the initial recipient - not that you may have multiple recipeints in some scenarios, so you can send the message to all of them by calling this method in a loop. this.UserId is the ID of the user that should receive the message (in this case it is a property of the Web part from which this code was taked from), please modify it to fit your scenario.
messageRep.SendMessageToUser(messageId, this.UserId, MessageStatus.Received, false);
//save the message in the "sent messages" folder of the currently active user.
messageRep.SendMessageToUser(messageId, SecurityUtility.GetUserId(), MessageStatus.Sent, false);

2
7/21/2011 6:02:16 AM
469 Reputation 60 Total posts

Thank you for your answer.

3
This is a demo site for MonoX. Please visit Mono Software for more info.