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 theemailarticleusingaround approvedthe Service Suite emailworkflowsclient, using both OAuth andmail-providerlegacycontrols.Addedemailchecksclients (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/APIAzureendpoint,setupauthentication,insenderConfiguringownership,EmailrecipientClientscontrols,forTLS,Outlookrate365limits,Accountsretryusingbehavior,Oauth2.0.andPassword
auditrequiredlogging.AddedThe
guidancefollowing method allows you toavoidsendhard-codedemail,passwords,butpersonaldoesmailboxes,notandrequiresensitiveatestpassword.datainvar 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 emailcontent.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();ValidationPasswordworkflownot requiredConfirmThe 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 theapprovedgivenmailuser.provider,
sendergraphServiceClient
identity,.Users[fromAddress]
recipient.SendMail(mailMessage,list,true)
and.Request()
allowed.PostAsync().Wait();
testreturndata"Emailbeforesuccessfullysendingsent.";
email.Validate}
authentication,catchTLS,(Exceptionrequestex)
payload,{
responsereturnstatus,"SendandEmailretry/errorFailed.\\r\\n"behavior+inex.Message;
a}
}
controlledrun.Review
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.