Problem:
When using the .Net Framework email classes in the System.Net.Mail namespace, the method to specify that the format of the mail is HTML.
Resolution:
Use the "IsBodyHTML" property on the System.Net.Mail.MailMessage class.
$set sourceformat"variable"
program-id. Program1 as "SMTP.Program1".
environment division.
configuration section.
repository.
class cMailMessage as "System.Net.Mail.MailMessage"
class cMailAddress as "System.Net.Mail.MailAddress"
class cSMTPClient as "System.Net.Mail.SmtpClient"
class cAttachment as "System.Net.Mail.Attachment"
class cMediaTypeNamesApp as "System.Net.Mime.MediaTypeNames Application"
.
data division.
working-storage section.
01 ws-mailmessage cMailMessage.
01 ws-smtpclient cSMTPClient.
78 mailfrom value "someone@microfocus.net".
78 mailto value "smtpuser@microfocus.com".
78 SmtpServer value "myserver".
78 mailsubject value "Auto Generated from COBOL on .Net".
78 mailbody value "<b>This is Line 1</b>." & x"0d0a" &
"This is Line 2.".
78 filename value "c:\\test.dat".
01 attFile cAttachment.
procedure division.
invoke cMailMessage::"New" returning ws-mailmessage.
set ws-mailmessage::"From" to cMailAddress::"New"(mailfrom)
invoke ws-mailmessage::"To"::"Add"(cMailAddress::"New"(mailto))
set ws-mailmessage::"Subject" to mailsubject
set ws-mailmessage::"Body" to mailbody
set ws-mailmessage::"IsBodyHtml" to true
set attFile to cAttachment::"New"(filename,cMediaTypeNamesApp::"Octet")
invoke ws-mailmessage::"Attachments"::"Add"(attFile)
set ws-smtpclient to cSMTPclient::"New"(SmtpServer)
invoke ws-smtpclient::"Send"(ws-mailmessage)
goback.
end program Program1.