Page 1 of 1
Send Email from X#
Posted: Tue Sep 06, 2022 10:05 am
by softdevo@tiscali.it
Hello everyone,
to send emails from my applications I use the System.Net.Mail.SmtpClient class for non-SSL emails and port 25, I use CDO.Message for SSL emails and on port 465. I would like to get rid of the ADODB.dll and cdosys DLLs .dll, but I can't find a solution except by resorting to third-party tools that I would like to avoid. Any suggestions?
Thank you
Danilo
Send Email from X#
Posted: Tue Sep 06, 2022 10:14 am
by wriedmann
Hi Danilo,
Ciao Danilo,
System.Net.Mail.SmtpClient e System.Net.Mail.MailMessage are your friends.
Code: Select all
oMessage := MailMessage{}
oMessage:Subject := cSubject
oMessage:Body := cMailBody
oMessage:Sender := MailAddress{ _cSender }
oMessage:@@From := MailAddress{ _cSender }
oMessage:@@to:Add( cAddress )
System.Net.ServicePointManager.SecurityProtocol := System.Net.SecurityProtocolType.Tls12
oSmtpClient := SmtpClient{}
oSmtpClient:Host := _cServerName
oSmtpClient:Port := _nPortNumber
oSmtpClient:DeliveryMethod := SmtpDeliveryMethod.Network
if _cUserName:Length > 1
oSmtpClient:UseDefaultCredentials := false
oSmtpClient:Credentials := NetworkCredential{ _cUserName, _cPassword }
endif
if _lUseSSL
oSmtpClient:EnableSsl := true
endif
oSmtpClient:Send( oMessage )
Wolfgang
Send Email from X#
Posted: Tue Sep 06, 2022 10:20 am
by softdevo@tiscali.it
Thanks Wolfgang,
I did this too but System.Net.Mail.SmtpClient has been marked as Obsolete for a while,
Danilo
Send Email from X#
Posted: Tue Sep 06, 2022 11:45 am
by wriedmann
Hi Danilo,
is is marked as obsolete only for Xamarin.
I'm not sure if it is worth to use an open source library like MimeKit:
http://www.mimekit.net/
Wolfgang
Send Email from X#
Posted: Tue Sep 06, 2022 3:45 pm
by ic2
Hello Wolfgang,
wriedmann post=23674 userid=336 wrote:is is marked as obsolete only for Xamarin.
That's true but it also says:
SmtpClient doesn't support many modern protocols.
In fact it only supports SMTP. If that is enough for Danilo's requirements, then it's fine, but if it is needs to be flexible probably not.
See also
https://docs.microsoft.com/en-us/dotnet ... ew=net-6.0
https://jonathancrozier.com/blog/smtpcl ... ur-net-app
https://github.com/dnnsoftware/Dnn.Platform/issues/3120
Normally I welcome it when Microsoft declares something obsolete, which means that they can't further ruin it as they usually do. But for this class I can imagine a ISP or mailserver which requires some security protocol which won't work then.
We use Chilkat for mail and many other things and this works very well..
Dick