Click or drag to resize

MessageControllerSendMessage Method

Authenticates the user and sends a new message to a list of recipients along with any specified attachments.

Namespace:  MedTunnelMsg.Controllers
Assembly:  MedTunnelMsg (in MedTunnelMsg.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public Task<Result> SendMessage()

Return Value

Type: TaskResult
Result.Data contains a Message object of the sent message. Result.ReturnCode values:
  • 0 = An unknown error occurred
  • 1 = Success
  • 2 = Application Invalid
  • 2 = Invalid User or Password
  • 6 = Required Item Missing: Message must contain text and/or at least one attachment
  • 7 = Message Password missing
  • 8 = Recipient(s) not found - recipientnames
  • 9 = File too large: thefilename
  • 12 = Access denied
  • 13 = Invalid Recipient: recipientname
  • 13 = Invalid Recipient: Email recipient must be the only recipient
  • 14 = Prohibited file type (offendingfiletype)
  • 99 = Message content not found in the Request body
Remarks
The Request must be sent as a MimeMultiPartContent request body containing the required Form fields and any file attachments. A message must contain at least Message Text or one or more Files.
  • ApplicationId - Passed as a Request Form field. Application Id
  • LocationId - Passed as a Request Form field. Location Id
  • MedTunnelId - Passed as a Request Form field. The User Name for the senders MedTunnel account
  • MedTunnelPassword - Passed as a Request Form field. The password for the sender's MedTunnel account
  • FromMailbox - Passed as a Request Form field. The mailbox the message will be sent from. Must be a mailbox the user has access to
  • To - Passed as a Request Form field. The MedTunnel Id or email address of the recipient. Can be a comma seperated list, but if sending to an email address it must be the only recipient
  • Body - Passed as a Request Form field. The message text
  • MessagePassword - Passed as a Request Form field. If sending to an email address this will be the password required to view the message. If not specified and a default password exist it will be used.
  • PatientMedTunnelId - Passed as a Request Form field. MedTunnel Id of the patient sending the message (only required for messages from patients)
  • ParentMessageId - Passed as a Request Form field. Specifies the parent message id if replying to a message
  • file1...filen - File attachments
Examples
C#
//namespaces to include
//using System;
//using System.Net;
//using System.Web.Script.Serialization;
//using System.IO;
//using System.Net.Http;
//using System.Net.Http.Headers;

string authKey = "";
string url;
string downloadString;
string dataToSend;
Result webResult;
JavaScriptSerializer serializer = new JavaScriptSerializer();

//if the session has expired then re-login
if (!SessionStillActive())
{
    authKey = Login();
}

//var provider = new MultipartMemoryStreamProvider();
//var content = new MultipartFormDataContent();

using (var client = new HttpClient())
{
    using (var content = new MultipartFormDataContent())
    {
        SendMessage message = new MedTunnelMsg.Models.SendMessage()
        {
            ApplicationId = "yourapplicationid",
            LocationId = "yourlocationid",
            MedTunnelId = "johndoe@doemedical",        //MedTunnelId of the user sending the message
            MedTunnelPassword = "myPassword",        //password of the MedTunnel user sending the message
            FromMailboxId = 0,                        //optional - will default to logged in user's mailbox
            EmailAddress = "jane@janesmedical",
            Body = "This can be any message text",
            MessagePassword = "",                    //only required for messages sent to an e-mail address
            PatientMedTunnelId = "",                //optional - only required for messages sent from a patient account
            ParentMessageId = 0                        //used when replying to a message
        };

        //add the Message object to the request
        content.Add(new StringContent(serializer.Serialize(message)));

        //add the file(s) selected in the web form to the request
        foreach (UploadedFile postedFile in FileUpload1.UploadedFiles)
        {
            //read the file contents into a byte array
            BinaryReader br = new BinaryReader(postedFile.InputStream);
            var fileContent = new ByteArrayContent(br.ReadBytes(Convert.ToInt32(postedFile.ContentLength)));

            fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = postedFile.FileName
            };

            content.Add(fileContent);
        }

        url = "https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage";
        client.DefaultRequestHeaders.Add("Authorization", authKey);
        var sendResult = client.PostAsync(url, content).Result;

        webResult = serializer.Deserialize<Result>(sendResult.Content.ReadAsStringAsync().Result);

        if (webResult.ReturnCode != 1)
        {
            throw new Exception("SendFailed");
        }
    }
}
PHP/Curl
Message text only
-----------------

curl https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k 
        -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" 
        -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" 
        -F "To=recipientsMedTunnelId" 
        -F "Body=Test of SendMessage"


Message with a file attachment
------------------------------

curl https://server.medtunnel.com/MedTunnelMsg/api/Message/SendMessage -X POST -k 
        -F "ApplicationId=yourApplicationId" -F "LocationId=yourLocationId" 
        -F "MedTunnelId=yourMedTunnelId" -F "MedTunnelPassword=yourMedTunnelPassword" 
        -F "To=recipientsMedTunnelId" 
        -F "Body=Test of SendMessage"
        -F "file1=@C:\temp\Desert.jpg"
See Also