@@ -85,20 +85,7 @@ public SendGridMessage CreateMessage(string from, string fromName, string to, IE
8585 if ( ! string . IsNullOrEmpty ( fromName ) )
8686 fromAddress . Name = fromName ;
8787 var recipients = new List < EmailAddress > { new EmailAddress ( to ) } ;
88- if ( cc != null )
89- {
90- foreach ( var item in cc )
91- {
92- try
93- {
94- recipients . Add ( new EmailAddress ( item ) ) ;
95- }
96- catch ( Exception ex )
97- {
98- _logger . LogWarning ( ex , $ "Unable to add { item } to email copy list") ;
99- }
100- }
101- }
88+
10289
10390 //Handle subjects
10491 if ( _serviceOptions . AddEnvironmentSuffix && ! _hostingEnvironment . IsProduction ( ) )
@@ -115,11 +102,30 @@ public SendGridMessage CreateMessage(string from, string fromName, string to, IE
115102 var plainTextBody = Regex . Replace ( bodyHtml , "<[^>]*>" , "" ) ;
116103
117104 //Build message
105+ SendGridMessage message = null ;
118106 if ( recipients . Count == 1 )
119- return MailHelper . CreateSingleEmail ( fromAddress , recipients [ 0 ] , subject , plainTextBody , bodyHtml ) ;
107+ message = MailHelper . CreateSingleEmail ( fromAddress , recipients [ 0 ] , subject , plainTextBody , bodyHtml ) ;
108+ else
109+ message = MailHelper . CreateSingleEmailToMultipleRecipients ( fromAddress , recipients , subject , plainTextBody , bodyHtml ) ;
110+
111+ //Add CC later based on limitation of SendGrid API
112+ if ( cc != null )
113+ {
114+ foreach ( var item in cc )
115+ {
116+ try
117+ {
118+ var toAdd = new EmailAddress ( item ) ;
119+ message . AddCc ( toAdd ) ;
120+ }
121+ catch ( Exception ex )
122+ {
123+ _logger . LogWarning ( ex , $ "Unable to add { item } to email copy list") ;
124+ }
125+ }
126+ }
120127
121- return MailHelper . CreateSingleEmailToMultipleRecipients ( fromAddress , recipients , subject , plainTextBody ,
122- bodyHtml ) ;
128+ return message ;
123129 }
124130
125131 /// <inheritdoc />
0 commit comments