Home > OS >  Sending email to multiple recipients fails
Sending email to multiple recipients fails

Time:09-17

I am trying to send the same automatic email to multiple email addresses but I can't get it to work.

[HttpGet("largeorderemail")]
        public IActionResult LargeOrderEmail()
        {
            try
            {
                //var bodyString = $"<h3>{msg}</h3><br/><p> Visit the site <a href='{Startup.appSettings.AllowOrigin}/lidarweb'> LiDAR GIS portal.</a></p>";
                var bodyString = $"<h3>email body</h3>"  
                                  <br/>"  
                var emailService = new Email { To = "[email protected]" };
                var response = emailService.ExecuteLargeOrder(bodyString);
                return Ok();
            }
            catch (Exception e)
            {
                Log.Error(e);
                return NotFound();
            }
        }

public async Task<Response> ExecuteLargeOrder(string bodyString)
        {
            var fromAddr = new EmailAddress(from, "Info");
            subject = "large order";
            var toAddr = new EmailAddress(to, "User");
            plainTextContent = "";
            htmlContent = bodyString;
            var msg = MailHelper.CreateSingleEmail(fromAddr, toAddr, subject, plainTextContent, htmlContent);
            var response = await client.SendEmailAsync(msg);
            return response;
        }

When I send an email to a single address, it works. Like so: var emailService = new Email { To = "[email protected]" }; but when I try something like this, it doesn't send the email var emailService = new Email { To = "[email protected], [email protected]" }; I also tried separating the address like so var emailService = new Email { To = "[email protected]; [email protected]" }; but this also doesn't work.

Any suggestions?

CodePudding user response:

Instead of putting Email addresses, try doing this way. Keep all your Email address in Array and try looping through the Array so that you can achieve your goal.

  • Related