MyChat add-ons: developing, technical questions, testing, documentation and other useful information
User avatar
Alona Kutsenko
This script sends a private message to the user's email if he is offline. To allow the script to send messages, a recipient and sender must fill correct email addresses in their profiles.

The script should be handled to the OnPrivateMessage event on MyChat Server:
offline-message-script.png
offline-message-script.png (85 KiB) Viewed 6228 times

Message sending does not impact the server's speed, so you have nothing to worry about.

Instead of sHost, sLogin, sPassword, and sPort you have to type parameters of your email server.

Code: Select all
const
  sHost     = 'mail.yourserver.com';
  sLogin    = '[email protected]';
  sPassword = 'secretpassword';
  iPort     = 26;
 
function OnPrivateMessage(iCID, iUIN, iUINTo, iMsgType: integer; sMsg: string): boolean;
var
  sEmailTo, sEmailFrom, sTextBody, sNameFrom, sNameTo: string;
begin
  result := true;
 
    if not mIsUINOnline(iUINTo) then begin
      sEmailTo   := mGetUserPrimaryEmail(iUINTo);
      sEmailFrom := mGetUserPrimaryEmail(iUIN);
     
        if (length(sEmailTo) > 0) and (length(sEmailFrom) > 0) then begin
          sNameFrom := mGetUserFullNameByPreset(iUIN, 0);
          sNameTo   := mGetUserFullNameByPreset(iUINTo, 0);
       
          sTextBody := '<span style="color:green">' +
                       FormatDateTime('[mm.dd.yyyy hh:nn:ss]', Now) +
                       '</span>' +
                       ' '+
                       '<span style="color:blue"><b>' +
                       sNameFrom +
                       '</b></span>'+
                       '&gt; '+
                       ReplaceString(mConvertMsgToPlainText(sMsg, iMsgType), CRLF, '</br>', true, false);
                       
          SendEmail(sHost, iPort, sLogin, sPassword, sEmailFrom, false, sEmailTo,
                    'MyChatoffline message for ' + sNameTo, sTextBody, 1, '');
        end;
    end;
end;

begin

end.


Share your ideas, if any :)