This property specifies the Digital Signature of current email.
ANSMTP uses CAPICOM object(a free component of Microsoft) to sign and encrypt email, CAPICOM is included in ANSMTP installation package. More detail about CAPICOM, please click here.
After you destroyed the Signer object or you no longer want to use Digital Signature, you should set Signer property to null.
Usage Example:
[Visual Baisc]
Private Sub SendEmail()
Dim oSmtp As New AOSMTPLib.Mail
Dim oStore As New CAPICOM.Store
Dim oCertificates As CAPICOM.Certificates
Dim oCertificate As CAPICOM.Certificate
Dim oSigner As New CAPICOM.Signer
Dim Sender As String
Sender = "test@adminsystem.net"
'Load certificate from CURRENT_USER_STORE
oStore.Open CAPICOM_CURRENT_USER_STORE, "My", CAPICOM_STORE_OPEN_READ_ONLY
Set oCertificates = oStore.Certificates.Find( CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, Sender )
If oCertificates.Count = 0 Then
MsgBox "no certificate found"
Exit Sub
End If
Set oCertificate = oCertificates.Item(1)
'You can also load certificate from a "pfx" file.
'How to load certificate from a file
'Set oCertificate = New CAPICOM.Certificate
'oCertificate.Load "c:\\cert\\my.pfx", "password of this certificate"
oSigner.Certificate = oCertificate
oSmtp.Signer = oSigner
oSmtp.ServerAddr = "mail.adminsystem.net"
oSmtp.FromAddr = Sender
oSmtp.AddRecipient "Support Team", "support@adminsystem.net", 0
oSmtp.Subject = "Test"
oSmtp.BodyText = "Hello, this is a test...."
If oSmtp.SendMail() = 0 Then
MsgBox "Message delivered!"
Else
MsgBox oSmtp.GetLastErrDescription()
End If
oSmtp.Signer = Nothing
Set oSigner = Nothing
End Sub
[C#]
using AOSMTPLib;
using CAPICOM;
private void SendEmail()
{
AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass();
StoreClass oStore = new StoreClass();
SignerClass oSigner = new SignerClass();
Certificates oCertificates = null;
Certificate oCertificate = null;
string Sender = "test@adminsystem.net"
oStore.Open( CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE,
"My", CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY );
oCertificates = (CAPICOM.Certificates)oStore.Certificates;
oCertificates = (Certificates)oCertificates.Find(
CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME,
Sender, true );
if( oCertificates.Count == 0 )
{
Console.WriteLine( "no certificate found" );
return;
}
oCertificate = (Certificate)oCertificates[1];
oSigner.Certificate = oCertificate;
oSmtp.Signer = oSigner;
oSmtp.ServerAddr = "mail.adminsystem.net";
oSmtp.FromAddr = Sender;
oSmtp.AddRecipient( "Support Team", "support@adminsystem.net", 0 );
oSmtp.Subject = "Test";
oSmtp.BodyText = "Hello, this is a test....";
if( oSmtp.SendMail() == 0 )
Console.WriteLine( "Message delivered!" );
else
Console.WriteLine( oSmtp.GetLastErrDescription());
oSmtp.Signer = null;
oSigner = null;
}
[Visual C++]
#include "stdafx.h"
#include <comdef.h>
#include <iostream>
#import "C:\Program Files\AdminSystem.NET\ANSMTP\CAPICOM.dll" \
no_namespace
#import "C:\Program Files\AdminSystem.NET\ANSMTP\AOSMTP.dll" \
rename_namespace("AOSMTPLib")
using namespace AOSMTPLib;
using namespace std;
void SendEmail()
{
::CoInitialize( NULL );
_bstr_t Sender;
Sender = _bstr_t( "test@adminsystem.net" );
IMailPtr oSmtp = NULL;
oSmtp.CreateInstance("AOSMTP.Mail");
IStorePtr oStore = NULL;
ISignerPtr oSigner = NULL;
ICertificates2Ptr oCertificates = NULL;
ICertificatePtr oCertificate = NULL;
oStore.CreateInstance("CAPICOM.Store");
oSigner.CreateInstance("CAPICOM.Signer");
oStore->Open( CAPICOM_CURRENT_USER_STORE,
_bstr_t("My"), CAPICOM_STORE_OPEN_READ_ONLY );
oCertificates = oStore->Certificates;
oCertificates = oCertificates->Find(
CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME,
Sender, (VARIANT_BOOL)TRUE );
if( oCertificates->Count == 0 )
{
cout << "no certificate found" << endl;
return;
}
oCertificate = oCertificates->Item[1];
oSigner->Certificate = oCertificate;
oSmtp->Signer = oSigner;
oSmtp->ServerAddr = _bstr_t( "mail.adminsystem.net" );
oSmtp->FromAddr = Sender;
oSmtp->AddRecipient( _bstr_t("Support Team"),
_bstr_t("support@adminsystem.net"), 0 );
oSmtp->Subject = _bstr_t("Test");
oSmtp->BodyText = _bstr_t("Hello, this is a test....");
if( oSmtp->SendMail() == 0 )
cout << "Message delivered!" << endl;
else
cout << (const char*)(oSmtp->GetLastErrDescription()) << endl;
oSmtp->Signer = NULL;
}
See Also
2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.