SendSmtpMail (with Attachments using SMTP)

The SendSmtpMail function is used to send a message with one or more attachments using direct SMTP e-mail. The SendSmtpMailW function is the Unicode equivalent of the same function. There are no "W" versions for the ActiveX interface, because the normal versions accept Unicode as well as non-Unicode strings.

 

Syntax

ActiveX:

System.Int32 SendSmtpMail(System.String szHostname, System.Int32 lPort, System.String szFrom, System.String szTo, System.String szCC, System.String szBCC, System.String szSubject, System.String szMessage, System.String szfilenames)

DLL:

long SendSmtpMail(LPCSTR szHostname, long lPort, LPCSTR szFrom, LPCSTR szTo, LPCSTR szCC, LPCSTR szBCC, LPCSTR szSubject, LPCSTR szMessage, LPCSTR szFilenames)
long SendSmtpMailW(LPCWSTR szHostname, long lPort, LPCWSTR szFrom, LPCWSTR szTo, LPCWSTR szCC, LPCWSTR szBCC, LPCWSTR szSubject, LPCWSTR szMessage, LPCWSTR szFilenames)

 

Parameters

szHostName

Name or IP address of server used to send e-mails.

lPort

SMTP port number on server used to send e-mails. The default value is 25.

szFrom

Name of the e-mail sender as it shows to the person receiving the e-mail.

szTo

Name and e-mail address of the e-mail destination. Multiple addresses can be specified by separating them with semi-colons (;).

szCC

Name and e-mail address of the e-mail Carbon Copy list. Multiple addresses can be specified by separating them with semi-colons (;).

szBCC

Handle Name and e-mail address of the e-mail Blind Carbon Copy list. Multiple addresses can be specified by separating them with semi-colons (;).

szSubject

Subject of the email.  Some servers require to use UTF8: as prefix to support Unicode text.

szMessage

E-mail message.

szFileNames

Series of file names and their captions as they should appear in the e-mail attachment. The file name is the full path of the file to send, the caption is the name of the file as seen by the recipient. The syntax for sending multiple files is as follows: file1;caption1;file2;caption2; etc.  No space allowed between the semicolon and the file path.

 

Return Value

The SendSmtpMail method returns 0 if successful or an SMTP specific error code if an error occurs when sending the e-mail.

 

Remarks

It  should be an Ansi string for SendSmtpMail or a Unicode string for SendSmtpMailW.

 

For secured SMTP, see SendSmtpMailEx Method.

 

The default time-outs could be changed using the SendSmtpMailTimeout Method.

 

Some SMTP servers don't allow direct Unicode for the text of the SMTP header, only UTF8 encoding.   In those cases, the UTF8:  prefix must be used for the subject field.  Ex: UTF8: Test subject ä ö ü Ä Ö Ü ß.  However, the conversion only will applied if there is any Unicode symbol.

 

Member of CDIntfEx.CDIntfEx.

 

Example

Public Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    Const AMYUNIPRINTERNAME As String = "Amyuni PDF Converter"

 

    ' Declare a new cdintfex object if it does not exist in the form.

    Dim PDF As New CDIntfEx.CDIntfEx

 

    ' Get a reference to the installed printer.

    ' This will fail if the printer name passed to the DriverInit method is 

    ' not found in the printer’s folder

    PDF.DriverInit(AMYUNIPRINTERNAME)

 

    ' The SetDefaultPrinter function sets the system default printer to the one

    ' initialized by the DriverInit functions.

    PDF.SetDefaultPrinter()

 

    ' The EnablePrinter() method needs to be called right before each print job.

    ' and before the configuration

    ' Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode)

 

    ' Set SendSmtpMail

    PDF.SendSmtpMail("smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",

                "Testing email capabilities", "Please find attached the requested document\nin PDF format.",

                "C:\temp1.pdf;document1.pdf;C:\temp2.pdf;document2.pdf")

 

    ' The RestoreDefaultPrinter function resets the system default printer 

    ' to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter()

 

    ' This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd()

End Sub

public void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

    const string AMYUNIPRINTERNAME = "Amyuni PDF Converter";

 

    // Declare a new cdintfex object if it does not exist in the form.

    CDIntfEx.CDIntfEx PDF = new CDIntfEx.CDIntfEx();

 

    // Get a reference to the installed printer.

    // This will fail if the printer name passed to the DriverInit method is 

    // not found in the printer’s folder

    PDF.DriverInit(AMYUNIPRINTERNAME);

 

    // The SetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    PDF.SetDefaultPrinter();

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    PDF.EnablePrinter(strLicenseTo, strActivationCode);

 

    // Set SendSmtpMail

    PDF.SendSmtpMail("smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",

        "Testing email capabilities", "Please find attached the requested document\nin PDF format.",

        "C:\temp1.pdf;document1.pdf;C:\temp2.pdf;document2.pdf");

 

    // The RestoreDefaultPrinter function resets the system default printer

    // to the printer that was the default before the call to SetDefaultPrinter.

    PDF.RestoreDefaultPrinter();

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    PDF.DriverEnd();

 

 

}

// PDF Converter Cpp.cpp : Defines the entry point for the console application.

// 

 

# include <Windows.h>

# include <string>

# include <iostream>

# include "CdIntf.h"

# pragma comment (lib, "CDIntf.lib")

 

using namespace std;

int main()

{

     // Constants for Activation codes

    #define strLicenseTo  "Amyuni PDF Converter Evaluation"

    #define strActivationCode "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

    #define AMYUNIPRINTERNAME "Amyuni PDF Converter"

 

    // Get a reference to the installed printer.

    // This will fail if the printer name passed to the DriverInit method is 

    // not found in the printer’s folder

    HANDLE PDF = DriverInit(AMYUNIPRINTERNAME);

 

    // The CDISetDefaultPrinter function sets the system default printer to the one

    // initialized by the DriverInit functions.

    CDISetDefaultPrinter(PDF);

 

    // The EnablePrinter() method needs to be called right before each print job.

    // and before the configuration

    // Calling the EnablePrinter() method will start a 20 second time-out value

    EnablePrinter(PDF, strLicenseTo, strActivationCode);

 

    // Set SendSmtpMail

    SendSmtpMail("smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",

        "Testing email capabilities", "Please find attached the requested document\nin PDF format.",

        "C:\temp1.pdf;document1.pdf;C:\temp2.pdf;document2.pdf");

 

    // The RestoreDefaultPrinter function resets the system default printer 

    // to the printer that was the default before the call to SetDefaultPrinter.

    RestoreDefaultPrinter(PDF);

 

    // This function will simply detach from an existing printer because the handle was created using DriverInit

    DriverEnd(PDF);  

 

    // Destroy PDF object

    PDF = nullptr;    

 

    return 0;

}

package Example;

 

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

 

public class Sample {

    public static void main(String[] args)

    {

        // Constants for Activation codes

        String strLicenseTo  = "Amyuni PDF Converter Evaluation";

        String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

        String AMYUNIPRINTERNAME = "Amyuni PDF Converter";

 

        // Declare a new cdintfex object if it does not exist in the form.

        ActiveXComponent pdf = new ActiveXComponent("CDIntfEx.CDIntfEx.6.5"); 

 

        // Get a reference to the installed printer.

        // This will fail if the printer name passed to the DriverInit method is 

        // not found in the printer’s folder

        Dispatch.call(pdf,"DriverInit",AMYUNIPRINTERNAME);

 

        // The SetDefaultPrinter function sets the system default printer to the one

        // initialized by the DriverInit functions.

        Dispatch.call(pdf,"SetDefaultPrinter");

 

        // The EnablePrinter() method needs to be called right before each print job.

        // and before the configuration

        // Calling the EnablePrinter() method will start a 20 second time-out value

        Dispatch.call(pdf,"EnablePrinter", strLicenseTo, strActivationCode);

 

        // Set SendSmtpMail

        Dispatch.call(pdf,"SendSmtpMail", "smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",

        "Testing email capabilities", "Please find attached the requested document\nin PDF format.",

        "C:\temp1.pdf;document1.pdf;C:\temp2.pdf;document2.pdf");

 

        // The RestoreDefaultPrinter function resets the system default printer 

        // to the printer that was the default before the call to SetDefaultPrinter.

        Dispatch.call(pdf,"RestoreDefaultPrinter"); 

 

        // This function will simply detach from an existing printer because the handle was created using DriverInit

        Dispatch.call(pdf,"DriverEnd");

 

    }

}

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

$AMYUNIPRINTERNAME = "Amyuni PDF Converter"

 

# Declare a new cdintfex object if it does not exist in the form.

$PDF = New-Object -ComObject CDIntfEx.CDIntfEx.6.5

 

# Get a reference to the installed printer.

# This will fail if the printer name passed to the DriverInit method is 

# not found in the printer’s folder

[System.__ComObject].InvokeMember('DriverInit', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$AMYUNIPRINTERNAME) 

 

# The SetDefaultPrinter function sets the system default printer to the one

# initialized by the DriverInit functions.

[System.__ComObject].InvokeMember('SetDefaultPrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null)

 

# The EnablePrinter()method needs to be called right before each print job.

# and before the configuration

# Calling the EnablePrinter()method will start a 20 second time-out value

[System.__ComObject].InvokeMember('EnablePrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, @($strLicenseTo, $strActivationCode))

 

# Set SendSmtpMail

[System.__ComObject].InvokeMember('SendSmtpMail', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF, 

    @("smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",

                "Testing email capabilities", "Please find attached the requested document\nin PDF format.",

                "C:\temp1.pdf;document1.pdf;C:\temp2.pdf;document2.pdf"))

 

# The RestoreDefaultPrinter function resets the system default printer 

# to the printer that was the default before the call to SetDefaultPrinter.

[System.__ComObject].InvokeMember('RestoreDefaultPrinter', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null) 

 

# This function will simply detach from an existing printer because the handle was created using DriverInit 

[System.__ComObject].InvokeMember('DriverEnd', [System.Reflection.BindingFlags]::InvokeMethod,$null,$PDF,$null) 

 

# Destroy PDF object

$PDF = $null

' Constants for Activation codes

Const strLicenseTo = "Amyuni Tech. Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

Const AMYUNIPRINTERNAME = "Amyuni PDF Converter"

 

'  Declare a new cdintfex object

Dim PDF

Set PDF = CreateObject("CDIntfEx.CDIntfEx.6.5")

 

' Get a reference to the installed printer.

' This will fail if the printer name passed to the DriverInit method is

' not found in the printer‚¬„¢s folder

PDF.DriverInit AMYUNIPRINTERNAME

 

' The SetDefaultPrinter function sets the system default printer to the one

' initialized by the DriverInit functions.

PDF.SetDefaultPrinter

 

' The EnablePrinter() method needs to be called right before each print job.

' and before the configuration

' Calling the EnablePrinter() method will start a 20 second time-out value

PDF.EnablePrinter strLicenseTo, strActivationCode

 

' Set SendSmtpMail

PDF.SendSmtpMail "smtp.amyuni.com", 25, "support@amyuni.com", "info@amyuni.com", "sales@amyuni.com", "",_

                 "Testing email capabilities", "Please find attached the requested document\nin PDF format.",_

                 "c:\temp\temp1.pdf;document1.pdf;c:\temp\temp2.pdf;document2.pdf"

 

' The RestoreDefaultPrinter function resets the system default printer

' to the printer that was the default before the call to SetDefaultPrinter.

PDF.RestoreDefaultPrinter

 

' This function will simply detach from an existing printer because the handle was created using DriverInit

PDF.DriverEnd

 

' Destroy PDF object

Set PDF = Nothing