Send Email from X#

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

Send Email from X#

Post 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
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Send Email from X#

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

Send Email from X#

Post by softdevo@tiscali.it »

Thanks Wolfgang,
I did this too but System.Net.Mail.SmtpClient has been marked as Obsolete for a while,

Danilo
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Send Email from X#

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Send Email from X#

Post 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
Post Reply