Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Digital signature in mail message created using MAPI

Digital signature in mail message created using MAPI

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiocryptographyhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Turosik
    wrote on last edited by
    #1

    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.

    R 1 Reply Last reply
    0
    • T Turosik

      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.

      R Offline
      R Offline
      rashin ghodratzade
      wrote on last edited by
      #2

      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"));
      }
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups