Email: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<strong>How to send emails.</strong> Emails are sent out using the EmailHelper.cs class. Here is an example: | <strong>How to send emails.</strong> Emails are sent out using the EmailHelper.cs class. Here is an example: | ||
< | <pre>var firmContacts = await dbContext.FirmContact | ||
.AsNoTracking() | .AsNoTracking() | ||
.Where(contact => contact.FirmKey == 1 | .Where(contact => contact.FirmKey == 1 |
Latest revision as of 18:52, 5 October 2023
How to send emails. Emails are sent out using the EmailHelper.cs class. Here is an example:
var firmContacts = await dbContext.FirmContact .AsNoTracking() .Where(contact => contact.FirmKey == 1 && contact.Email != null && contact.Email != "" && contact.EmailTags.Contains("Foo") ) .ToListAsync(); if (firmContacts.Count() == 0) { return; } var emailFrom = await emailService.GetDoNotReplyEmailAddress(); if (string.IsNullOrWhiteSpace(emailFrom)) { return; } var emailTemplate = await emailTemplateService.GetByTemplateId("Foo"); if (emailTemplate == null) { return; } var emailToList = EmailHelper.GetEmailList(firmContacts.Select(p => p.Email)); var templateData = new { foo, }; var stubble = new StubbleBuilder().Build(); var emailSubject = await stubble.RenderAsync(emailTemplate.Subject, templateData); var emailBody = await stubble.RenderAsync(emailTemplate.Body, templateData); //var exportReportResult = await reportService.ExportReport(model); //var attachments = new List<Attachment>(); //attachments.Add(new Attachment( // exportFirmReportResult.Stream, // $"foo-bar-{DateTime.UtcNow.ToString("yyyyMMdd")}.pdf", // exportReportResult.ContentType // )); EmailHelper.SendEmailWithAttachment( emailFrom, emailToList, null, null, emailSubject, emailBody, null/*attachments*/ );
Test sending emails from Novus-Server by running e.g. curl -v -H 'Content-Type:application/json' -d '{"From":"donotreply@kiwanatechnologies.com","To":"albert.chan@visfuture.com,dgriffin@mayerglobal.com,hanika.dsouza@visfuture.com,tony.defeo@kiwanatechnologies.com","Subject":"Test email (NovusBackEnd)","Content":"Test email. Please ignore."}' https://novusapi.kiwanatechnologies.com/api/foo2/email.
Azure Functions resource. Currently, there’s no test method to test a test email from an Azure Functions resource in the Novus.AzureFunction project. We will have to create a new Azure function, perhaps one that uses a HTTP trigger.
Return to Programming Guide