Skip to main content

Sending Email from Service Suite

UseYou this article when a Service Suite workflow needs tocan send email through an approved mail provider or internal SMTP path.

What changed in this article

  • Updated the email articleusing around approvedthe Service Suite email workflowsclient, using both OAuth and mail-providerlegacy controls.
  • Addedemail checksclients (such as gmail). with To, From, cc, subject, body, bcc parameters and attachments.

    OAuth cannot send emails on behalf of a user; they must be sent from a service account that acts on behalf of the application itself. This is similar to the process documented for SMTP/APIAzure endpoint,setup authentication,in senderConfiguring ownership,Email recipientClients controls,for TLS,Outlook rate365 limits,Accounts retryusing behavior,Oauth2.0.

    and

    Password auditrequired

    logging.
  • Added

    The guidancefollowing method allows you to avoidsend hard-codedemail, passwords,but personaldoes mailboxes,not andrequire sensitivea testpassword.

    data
    in
    var mailService = createOAuthMailClient("dummy@example.com", "QWERTYpoi123!",
        "QWPg646HDmAVa8dnABtTfdKgd6eZPujvtXXYYKM=", "7899fa0a-a899-481c-bdc2-132eec26f708",
        "d9d0bb61-6874-4c0e-8cae-59ad5bce1d4e");
        
    mailService.loginWithOAuth();

    var msg = mailService.createMailMessage("Email subject","Email body");

    //add recipients
    msg.addTo(["user1@appvance.com"]);
    msg.addCC(["user2@appvance.ai"]);
    msg.addBCC(["user3@appvance.com"]);

    //add attachment
    msg.addAttachment("prueba.jpeg", readBytes("{ds}/test.jpeg"));

    //verify email content.was sent
    var sent = mailService.sendEmail(msg);
    assertTrue(sent);

    //****validations****
    wait(10000);

    //refresh folder or switch to another folder
    mailService.setFromFolder("INBOX");

    //get last unread message 
    var lastUnread = mailService.getLastUnreadMessages(1);
    assertTrue(lastUnread.length === 1);

    //get all emails
    var allEmails = mailService.getAllMessages();
    assertTrue(allEmails.length === mailService.getMessageCount());


    mailService.logout();

    ValidationPassword workflownot required

    1. Confirm

      The following method allows you to send email, but does not require a password. This method uses GraphServiceClient.

      public string SendEmail(string fromAddress, string toAddress, string CcAddress, string subject, string message, string tenanatID , string clientID , string clientSecret)
          {
                  try
                  {
                  
                  var credentials = new ClientSecretCredential(
                                      tenanatID, clientID, clientSecret,
                                  new TokenCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud });
                  GraphServiceClient graphServiceClient = new GraphServiceClient(credentials);


                  string[] toMail = toAddress.Split(',');
                  List<Recipient> toRecipients = new List<Recipient>();
                  int i = 0;
                  for (i = 0; i < toMail.Count(); i++)
                  {
                      Recipient toRecipient = new Recipient();
                      EmailAddress toEmailAddress = new EmailAddress();

                      toEmailAddress.Address = toMail[i];
                      toRecipient.EmailAddress = toEmailAddress;
                      toRecipients.Add(toRecipient);
                  }

                  List<Recipient> ccRecipients = new List<Recipient>();
                  if (!string.IsNullOrEmpty(CcAddress))
                  {
                      string[] ccMail = CcAddress.Split(',');
                      int j = 0;
                      for (j = 0; j < ccMail.Count(); j++)
                      {
                          Recipient ccRecipient = new Recipient();
                          EmailAddress ccEmailAddress = new EmailAddress();

                          ccEmailAddress.Address = ccMail[j];
                          ccRecipient.EmailAddress = ccEmailAddress;
                          ccRecipients.Add(ccRecipient);
                      }
                  }
                  var mailMessage = new Message
                  {
                      Subject = subject,

                      Body = new ItemBody
                      {
                          ContentType = BodyType.Html,
                          Content = message
                      },
                      ToRecipients = toRecipients,
                      CcRecipients = ccRecipients

                  };
                  // Send mail as the approvedgiven mailuser. provider,
                  sendergraphServiceClient
                     identity,.Users[fromAddress]
                      recipient.SendMail(mailMessage, list,true)
                      and.Request()
                      allowed.PostAsync().Wait();

                  testreturn data"Email beforesuccessfully sendingsent.";

              email.
    2. Validate}
              authentication,catch TLS,(Exception requestex)
              payload,{

                  responsereturn status,"Send andEmail retry/errorFailed.\\r\\n" behavior+ inex.Message;
              a}
      }
    controlled run.
  • Review
logs and received messages without exposing passwords, tokens, or sensitive customer data.

Review note: This page now treats email sending as an integration with data-transmission risk controls.


Last updated: OctoberJanuary 5,16, 20262024

If you have any feedback on this topic, please contact us at documentation@appvance.ai.