Digital signature in mail message created using MAPI
-
Hello. I made a simple C++ program in Visual Studio 6 (MFC SDI). It sends a mail message using MAPI (mapi32.dll) and it works great and is easy to use. But I don't undestannd how to attach a digital signature (stored in local certificates) to my message. Outlook is set to add digital signature to all new messages but it ignores messages created by my C++ program. Please help. Best regards, Alex.
-
Hello. I made a simple C++ program in Visual Studio 6 (MFC SDI). It sends a mail message using MAPI (mapi32.dll) and it works great and is easy to use. But I don't undestannd how to attach a digital signature (stored in local certificates) to my message. Outlook is set to add digital signature to all new messages but it ignores messages created by my C++ program. Please help. Best regards, Alex.
Digital signature prevents email content is faked or changed in transport level. Encrypting email protects email content from exposure to inappropriate recipients. Both digital signature and email encrypting depend on digital certificate.
If you have an email digital signature certificate installed on your machine, you can find it in Control Panel-interner option-content-Certificates-Personal
Then you can use your email certificate to sign the email by the following code. If you don't have a certificate for your email address, you MUST get a digital certificate for personal email protection from third-party certificate authorities such as www.verisign.com.
#include "stdafx.h"#include "easendmailobj.tlh"
using namespace EASendMailObjLib;int _tmain(int argc, _TCHAR* argv[])
{
::CoInitialize( NULL );IMailPtr oSmtp = NULL; oSmtp.CreateInstance( "EASendMailObj.Mail"); oSmtp->LicenseCode = \_T("TryIt"); // Set your sender email address oSmtp->FromAddr = \_T("test@emailarchitect.net"); // Add recipient email address oSmtp->AddRecipientEx( \_T("support@emailarchitect.net"), 0 ); // Set email subject oSmtp->Subject = \_T("email from Visual C++ with digital signature(S/MIME)"); // Set email body oSmtp->BodyText = \_T("this is a test email sent from Visual C++ with digital signature"); // Your SMTP server address oSmtp->ServerAddr = \_T("smtp.emailarchitect.net"); // User and password for ESMTP authentication, if your server doesn't // require User authentication, please remove the following codes. oSmtp->UserName = \_T("test@emailarchitect.net"); oSmtp->Password = \_T("testpassword"); // If your SMTP server requires SSL connection, please add this line //oSmtp->SSL\_init(); // Add signer digital signature if( oSmtp->SignerCert->FindSubject(\_T("test@emailarchitect.net"), CERT\_SYSTEM\_STORE\_CURRENT\_USER , \_T("my")) == VARIANT\_FALSE ) { \_tprintf(\_T("Error with signer certificate; %s\\r\\n"), (const TCHAR\*)oSmtp->SignerCert->GetLastError()); return 0; } if( oSmtp->SignerCert->HasPrivateKey == VARIANT\_FALSE ) { \_tprintf(\_T("certificate does not have a private key, it can not sign email.\\r\\n" )); return 0; } \_tprintf(\_T("Start to send email ...\\r\\n" )); if( oSmtp->SendMail() == 0 ) { \_tprintf( \_T("email was sent successfully!\\r\\n")); }