Secure Exchanges SDK Documentation
Search Results for

    Show / Hide Table of Contents

    Envoi multi-destinataires

    Ce guide explique comment envoyer un message a plusieurs destinataires.

    Concept

    Avec MutliRecipientArgs, vous pouvez envoyer le meme message a plusieurs personnes. Chaque destinataire recoit son propre lien securise.

    Exemple rapide

    var recipients = new List<RecipientInfo>
    {
        new RecipientInfo { Email = "destinataire1@example.com" },
        new RecipientInfo { Email = "destinataire2@example.com" },
        new RecipientInfo { Email = "destinataire3@example.com" }
    };
    
    Uri endpoint = new Uri("https://www.secure-exchanges.com/_api/0217/0217.asmx");
    
    var args = new MutliRecipientArgs(
        endpoint, serial, apiUser, apiPassword,
        recipients,
        "Message pour tous",
        "Sujet",
        null, null, SendMethodEnum.onlyEmail,
        false, true, true, "fr-CA", 5, 1440
    );
    
    var response = MessageHelper.MultiRecipientMessage(args);
    
    // Chaque destinataire a sa propre reponse
    foreach (var recipientAnswer in response.RecipientsAnswer)
    {
        Console.WriteLine($"URL: {recipientAnswer.Answer.URL}");
    }
    

    Exemple complet : Diffusion d'informations RH

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using SecureExchangesSDK.Helpers;
    using SecureExchangesSDK.Models.Args;
    using SecureExchangesSDK.Models.Entity;
    using SecureExchangesSDK.SecureExchanges;
    
    public class HRCommunicationService
    {
        private readonly Guid _serial;
        private readonly Guid _apiUser;
        private readonly Guid _apiPassword;
    
        public HRCommunicationService(Guid serial, Guid apiUser, Guid apiPassword)
        {
            _serial = serial;
            _apiUser = apiUser;
            _apiPassword = apiPassword;
        }
    
        /// <summary>
        /// Envoie un bulletin RH confidentiel a tous les employes
        /// </summary>
        public BroadcastResult SendHRBulletin(
            List<Employee> employees,
            string subject,
            string htmlContent,
            List<string> attachmentPaths = null)
        {
            // Convertir les employes en RecipientInfo
            var recipients = employees
                .Where(e => !string.IsNullOrEmpty(e.Email))
                .Select(e => new RecipientInfo { Email = e.Email })
                .ToList();
    
            if (!recipients.Any())
                return new BroadcastResult { Success = false, Error = "Aucun destinataire valide" };
    
            // Configuration
            Uri endpoint = new Uri("https://www.secure-exchanges.com/_api/0217/0217.asmx");
    
            var args = new MutliRecipientArgs(
                endpoint,
                _serial,
                _apiUser,
                _apiPassword,
                recipients,
                htmlContent,
                subject,
                password: null,
                filesList: null,
                SendMethodEnum.onlyEmail,
                sendByMyOwnSMTPServer: false,
                showSubject: true,
                getNotify: false,  // Pas de notification pour les envois massifs
                culture: "fr-CA",
                maxOpeningTime: 10,
                expirationMinutes: 43200  // 30 jours
            );
    
            if (attachmentPaths != null)
                args.FilesPath = attachmentPaths;
    
            // Envoi
            var response = MessageHelper.MultiRecipientMessage(args);
    
            if (response.Status == 200)
            {
                var results = new List<RecipientResult>();
    
                for (int i = 0; i < response.RecipientsAnswer.Count; i++)
                {
                    var answer = response.RecipientsAnswer[i].Answer;
                    results.Add(new RecipientResult
                    {
                        Email = recipients[i].Email,
                        Success = answer.Status == 200,
                        MessageUrl = answer.URL,
                        Error = answer.Status != 200 ? "Echec d'envoi" : null
                    });
                }
    
                return new BroadcastResult
                {
                    Success = true,
                    TotalRecipients = recipients.Count,
                    SuccessCount = results.Count(r => r.Success),
                    FailedCount = results.Count(r => !r.Success),
                    RecipientResults = results
                };
            }
    
            return new BroadcastResult
            {
                Success = false,
                Error = response.Data
            };
        }
    }
    
    public class Employee
    {
        public string Email { get; set; }
        public string Name { get; set; }
        public string Department { get; set; }
    }
    
    public class BroadcastResult
    {
        public bool Success { get; set; }
        public string Error { get; set; }
        public int TotalRecipients { get; set; }
        public int SuccessCount { get; set; }
        public int FailedCount { get; set; }
        public List<RecipientResult> RecipientResults { get; set; }
    }
    
    public class RecipientResult
    {
        public string Email { get; set; }
        public bool Success { get; set; }
        public string MessageUrl { get; set; }
        public string Error { get; set; }
    }
    

    Bonnes pratiques

    • Limitez le nombre de destinataires par envoi (recommande : max 100)
    • Desactivez les notifications (getNotify: false) pour les envois massifs
    • Gerez les erreurs individuelles - certains destinataires peuvent echouer

    Voir aussi

    • Premier message
    • Messages avec fichiers
    In this article
    Back to top Secure Exchanges Inc. - Documentation