WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: seckner on January 14, 2019, 10:09:39 AM

Title: CLR and System.Net.Mail.MailAddress
Post by: seckner on January 14, 2019, 10:09:39 AM
Please be patient, I'm brand new to trying to understand both .NET and CLR. I found the code in the database for sending SMTP mail using .NET and it's been running for me for a while very successfully. Of course, now we need to modify it by sending TO more than one person. It will currently only send to a single email address, even if more than one address is listed.

MailAddress_From = ObjectClrNew( "System.Net.Mail.MailAddress", "FromA@email.com" )  will work
MailAddress_From = ObjectClrNew( "System.Net.Mail.MailAddress", "FromA@email.com, FromB@email.com" )  will work BUT only "FromB" will actually be sent

Searching on StackOverflow I've found both the   .To.Add   and  .Collection  commands but when I try to use either I always get an error  1848: CLR: Type name not found. Could I get some help in figuring out how to add the second To address?

Thanks for any help!

Title: Re: CLR and System.Net.Mail.MailAddress
Post by: td on January 14, 2019, 10:44:34 AM
The "To" property of the "MailMessage" object returns a collection so to add an additional "to" address you need to call the collection's "Add" method:

Code (winbatch) Select
MailMessage = ObjectClrNew( 'System.Net.Mail.MailMessage', MailAddress_From, MailAddress_To )
MailAddress_To2 = ObjectClrNew( 'System.Net.Mail.MailAddress', 'guesswho@winbatch.com' )
MailMessage.To.Add(MailAddress_To2)


Title: Re: CLR and System.Net.Mail.MailAddress
Post by: seckner on January 14, 2019, 11:50:43 AM
Thank you so much!
Title: Re: CLR and System.Net.Mail.MailAddress
Post by: td on January 14, 2019, 02:14:39 PM
You were almost there already.