How to enhance your VO application with X# - the SendMail DLL

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to enhance your VO application with X# - the SendMail DLL

Post by wriedmann »

Often some things are hard or impossible to accomplish in VO applications, but easy in X# applications because the .NET framework has the required functionalities.

One of the VO shortcomings is the possibility to send mail through GMail: SSL is required and the VO cSMTP classes cannot use SSL because the Windows API seems to not have the needed functionality.

Therefore I created a simple X# DLL, named SendMail.DLL that exposes a class interface ISmtpSender through COM and use this DLL in my VO applications.

You can find this DLL together with a VO sample application and the relative source code in XIDE export format attached to this message.

Of course you can enhance this DLL as needed, but please generate a new SNK file and new GUIDs for your own version. I'm using exactly this DLL in several of my applications.

The DLL must be located in the directory of the executable, otherwise SideBySide will not work.

The entire mechanism is a bit unstable until you understand how this works: it is a game between the COM interface of the DLL, the DLL manifest (generated by mt.exe) and the manifest of the executable. And please pay particular attention to the version info: they must match!

This is the content of the readme in the DLL source code:

Code: Select all

1) create key file with 
sn - k sendmail.snk
2) after building and signing the DLL, read the public key with
sn -T sendmail.dll
(upper case T)
3) create the TLB with elevated rights
regasm sendmail.dll /tlb
4) remove the registration
regasm sendmail.dll /unregister                                                  
5) create the automation server in VO
6) add cClsID and cProdId in the Init method
7) create the manifest for the DLL
mt.exe -managedassemblyname:sendmail.dll -nodependency -out:sendmail.dll.manifest  
8) adjust the manifest (remove "msil" and add "win32")

Caveats:
- the namespace should be set also in the DLL properties, can be identical to the DLL file name
- the class CANNOT have the same name as the DLL 

Debugging (if the VO application does not starts):
sxstrace Trace -logfile:systrace.out
sxstrace Parse -logfile:systrace.out -outfile:sxstrace.txt
notepad sxstrace.txt
Happy mailing!

Wolfgang
Attachments
SendMailCOM.zip
(30.09 KiB) Downloaded 107 times
Last edited by ConradB on Sun Aug 06, 2017 1:22 pm, edited 1 time in total.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to enhance your VO application with X# - the SendMail DLL

Post by wriedmann »

A few days after posting this sample, I have received a email with the following text (quoting only the important part):
I started the tests and achieved the following results.

For mailserver without SSL, the email is sent without any problem.

For SSL mailserver:
Smtp.gmail.com
Port: 587
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Note: Login and Password are entered correctly.
Port: 465
Failure sending mail.

Smtp.abv.bg
Failure sending mail.

Smtp.live.com
The e-mail is sent without any problem.

I want to ask if the problem is in the servers or I have not done the right thing.
I have answered as follows:
with gmail my sample works, I have tested it. But to have SMTP working with GMail, you have to enable „less secure applications“ in the web interface. Otherwise Google requires an authentication type that is nearly impossible to implement.

For the other SMTP servers I cannot say anything as I don’t know the specifics.
Unfortunately there are two possible SMTP SSL types: TLS and SMTPS (mostly over port 465).

The .NET classes unfortunately support only TLS. Please see here for more informations:

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl(v=vs.110).aspx

So because of this my sample cannot support SMTPS like no other software based on the .NET Framework classes can do this.

Maybe Microsoft later decides to support it, or maybe someone releases a free implementation (but I have my doubts).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to enhance your VO application with X# - the SendMail DLL

Post by wriedmann »

Hello for who is interested,
I have now found an issue: the compile of the sendmail.dll works only if you have Vulcan.NET installed on your machine. Otherwise the needed manifest is not correctly embedded into the DLL.
Do make it work, the content of the file Manifest.CREATEPROCESS_MANIFEST_RESOURCE_ID.rc has to be changed from

Code: Select all

CREATEPROCESS_MANIFEST_RESOURCE_ID RC_RT_MANIFEST "SendMail.manifest"
to

Code: Select all

#define RC_RT_MANIFEST 24
CREATEPROCESS_MANIFEST_RESOURCE_ID RC_RT_MANIFEST "SendMail.manifest"
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply