Esempio n. 1
0
        public MultiRecipientAnswer MultiSendEmailWithLocalFiles()
        {
            // Create a files list path : physical path
            List <string> files = new List <string>();

            // Get the project path


            // Append the file to send and encrypt
            files.Add(Path.Combine(RootPath, "Files", "logo-full.png"));

            // Fill this list if your have memory file to encrypt and send has attachment
            List <FileArgs> filesArgs = null;

            // Configure the message body, and the subject
            string HTMLBody     = "<strong>This is my html message</strong>";
            string EmailSubject = "This is my public subject";

            // Create a list of recipient. Phone number could be filled to received SMS
            // WARNING : the SendMethodEnum must be set to msgEmailCodeSms to received an email with a sms code to open it
            List <RecipientInfo> recipients = new List <RecipientInfo>();

            // Please enter the email and Phone number here
            recipients.Add(new RecipientInfo()
            {
                Email = "*****@*****.**", Phone = ""
            });

            // That is a password protection level
            string messagePassword = _globalPassword;

            // Define the sending mode
            // OnlyEmail - no additional protection, only a email need to provide the email in the recipient
            // msgSMSOnly - no additional protection, only a sms       need to provide the phone number in the recipient
            // msgEmailCodeSms - send a email with a 6 digit autogenerated code by sms, need to provide the phone number and email in each in the recipient
            // msgSMSCodeEmail  - send a SMS with a 6 digit autogenerated code by email, need to provide the phone number and email in each in the recipient
            SendMethodEnum sendingMode = SendMethodEnum.onlyEmail;

            // If set to true, will return the HTML message obfuscated, and protected, you need to send it by email
            // If set to false, Secure Exchanges will send the message for you
            bool sendMessageByMyself = true;

            // Received the notify by email, when the message will be read
            bool getNotify = true;
            // The culture of the message. Currently support "fr-CA" and "en-CA"
            string culture = "fr-CA";
            //Create the message args
            var args = new MutliRecipientArgs(
                EndPointURI,
                TestSerialNumber,
                TestAPIUser,
                TestAPIPsw,
                recipients,
                HTMLBody,
                EmailSubject,
                messagePassword,
                filesArgs,
                sendingMode,
                sendMessageByMyself,
                true,
                getNotify, culture, 1, 5)
            {
                FilesPath = files
            };
            // Call the multicecipient method
            MultiRecipientAnswer answer = MessageHelper.MultiRecipientMessage(args);

            // if the status is set to 200 the call was made successfully. See in answer.Data if the status is not 200
            if (answer.Status == 200)
            {
                foreach (var a in answer.RecipientsAnswer)
                {
                    // Here use a.Answer.HtmlMsg to send your email with your SMTP server
                    // a.Answer.Guid -- this is the reference of a messageid. Keep it in your système to retreived log about this message
                }
            }
            else
            {
                throw new Exception($"Erreur {answer.Status}");
            }
            return(answer);
        }
Esempio n. 2
0
        public void SendSignFile()
        {
            // Create a list of recipient. Phone number could be filled to received SMS
            // WARNING : the SendMethodEnum must be set to msgEmailCodeSms to received an email with a sms code to open it
            List <RecipientInfo> recipients = new List <RecipientInfo>();

            recipients.Add(new RecipientInfo()
            {
                Email = "*****@*****.**", Phone = ""
            });
            recipients.Add(new RecipientInfo()
            {
                Email = "*****@*****.**", Phone = ""
            });

            // Create a files list path : physical path
            List <string> files = new List <string>();

            // The PDF File that need to be signed
            files.Add(Path.Combine(RootPath, "Files", "model.pdf"));

            /// Load the template associated with that serial number
            var loadTemplateAnswer = SerialHelper.LoadSignsTemplate(new LoadSignsTemplateArgs()
            {
                EndPointUri = EndPointURI,
                Serial      = TestSerialNumber,
                ApiUser     = TestAPIUser,
                ApiPassword = TestAPIPsw
            });

            // Create a list of SignFilesRequired
            List <SignFilesRequired> signFiles = new List <SignFilesRequired>();

            // Create a dictionnary of recipients info with FileDefinition signatures
            Dictionary <RecipientInfo, List <FileZoneDefinition> > recipientIndex = new Dictionary <RecipientInfo, List <FileZoneDefinition> >();

            // Identify in the list of files, the file need to be signed
            foreach (string f in files)
            {
                // Retreived the SHA512 of file need to be signed
                string SHA512 = CryptoHelper.GetSHA512OfFile(f);
                // Add that checksum to the signFilesRequired list
                signFiles.Add(new SignFilesRequired()
                {
                    SHA512 = SHA512
                });
                // Because the name of the zones defined in the template are client 1, client 2, ...
                int clientPos = 1;
                // iterate trhow the recipient to specify the defines zone for the specific file for each recipients
                foreach (var r in recipients)
                {
                    // Validate that we found template. If no template exist, the signature will be in freemode
                    if (loadTemplateAnswer.Status == 200 && loadTemplateAnswer.Template != null)
                    {
                        // Find the right Zonefiles definition for that file. We search the template by filename, because we juste saved the template with
                        // the file name in the system
                        // We could also find the right template by the checksum, but the checksum of the file must be identical of the template item.FileDefinition.UniqueName == SHA512
                        var template = loadTemplateAnswer.Template.Find(item => string.Compare(item.Name, Path.GetFileName(f), true) == 0);
                        if (template != null)
                        {
                            // We add to the dictionnary the definition zone for that recipient. client 1 = recipient1, client2 = recipient2 etc ...
                            SignHelper.AddFileZoneDefToRecipientIndex(recipientIndex, template.FileDefinition.ZonesDef, SHA512,
                                                                      new KeyValuePair <string, RecipientInfo>($"client {clientPos}", r));
                        }
                    }
                    clientPos++;
                }
            }

            // Configure the message body, and the subject
            string HTMLBody     = "<strong>Please sign the files</strong>";
            string EmailSubject = "Sign file";
            string psw          = "protected";
            // Let you send the mail with your own smtp server
            bool sendWitMyOwnSMPTServer = false;


            //Create the message args
            var args = new MutliRecipientArgs(
                EndPointURI,
                TestSerialNumber,
                TestAPIUser,
                TestAPIPsw,
                recipients,
                HTMLBody,
                EmailSubject,
                psw,
                null,
                SecureExchangesSDK.SecureExchanges.SendMethodEnum.onlyEmail,
                sendWitMyOwnSMPTServer,
                true,
                true, "fr-CA", 1, 5)
            {
                FilesPath = files
            };

            // Because we have some file to sign, we add them to the args
            // Notes that you can send files witout signature only to the first recipient, if you have multiple recipient.
            if (signFiles.Count > 0)
            {
                // Set the files to be sign
                args.FileToSign = signFiles;
                // If the owner of the licence need to sign the file, set the value to false.
                // If it's set to false, the licence owner will receive an email when the file will be ready to sign by him
                args.OwnerDontNeedToSign = true;
                // Set the recipient zone definition
                args.SignRecipientsZoneDef = SignHelper.ConvertRecipientIndexToList(recipientIndex);
            }

            // Call the multicecipient method
            MultiRecipientAnswer answer = MessageHelper.MultiRecipientMessage(args);

            if (answer.Status == 200)
            {
                foreach (var a in answer.RecipientsAnswer)
                {
                    // Here use a.Answer.HtmlMsg to send your email with your SMTP server
                    // a.Answer.Guid -- this is the reference of a messageid. Keep it in your système to retreived log about this message
                }
            }
            else
            {
                throw new Exception($"Erreur {answer.Status}");
            }
        }