SimpleSendAttachment Method
Previous  Top  Next


SimpleSendAttachment method sends simple text or HTML e-mail with attachments to one or more recipients synchronously.

Syntax

[Visual Basic]


Function
 SimpleSendAttachment(strFrom As String, strTo As String, strSubject As String, strMessage As String, strAttach As StringByRef strError As String) As Long

Example:

Dim
 strError As String
Dim
 numResultCode As Long
numResultCode = objSmtpMail.SimpleSendAttachment("My Name <me@myisp.com>", "Someone <someone@someisp.com>;someoneelse@someotherisp.com", "test", "Test message", "c:\files\doc1.pdf;c:\files\doc2.pdf", strError)

[VBScript]


Function
 SimpleSendAttachmentScriptable(strFrom, strTo, strSubject, strMessage, strAttach, ByRef strError)

Example:

Dim
 strError
Dim
 numResultCode
numResultCode = objSmtpMail.SimpleSendAttachmentScriptable("My Name <me@myisp.com>", "Someone <someone@someisp.com>;someoneelse@someotherisp.com", "test", "Test message", "c:\files\doc1.pdf;c:\files\doc2.pdf", strError)

[C#]


int
 SimpleSendAttachment(string strFrom, string strTo, string strSubject, string strMessage, string strAttach, out string strError);

Example:

string
 strError;
int
 numResultCode = objSmtpMail.SimpleSendAttachment("My Name <me@myisp.com>", "Someone <someone@someisp.com>;someoneelse@someotherisp.com", "test", "Test message", "c:\\files\\doc1.pdf;c:\\files\\doc2.pdf", out strError);

[C++]


HRESULT SimpleSendAttachment(BSTR strFrom, BSTR strTo, BSTR strSubject, BSTR strMessage, BSTR strAttach, BSTR* pstrError, LONG* pnumResultCode);

Example:

BSTR bstr;
int numResultCode = spSmtpMail->SimpleSendAttachment("My Name <me@myisp.com>", "Someone <someone@someisp.com>;someoneelse@someotherisp.com", "test", "Test message", "c:\\files\\doc1.pdf;c:\\files\\doc2.pdf", &bstr);
_bstr_t strError(bstr, FALSE);


Parameters

strFrom [in]
Sender's e-mail address. You can also specify sender's name followed by the sender's e-mail address in angled brackets.

strTo [in]
List of recipients' e-mail addresses separated by semicolon. You can also specify recipient's name followed by the recipient's e-mail address in angled brackets.

strSubject [in]
Subject of the e-mail message.

strMessage [in]
Body of the e-mail message.

strAttach [in]
List of attachments separated by semicolon.

strError [out]
Contains extended error information if the message failed to be sent, empty string otherwise.

Return value

Returns numeric result:
0 if the message was sent successfully;
-1 if connection to the server failed or in case of other Winsock errors;
>0 SMTP error code as defined in RFC 821
page 34-35.

Remarks

SimpleSendAttachment can be used to send text or HTML e-mails. Body of the e-mail message should start with <html> tag for HTML e-mail messages. This method supports Unicode in the subject and body of the message as well as in the sender's and recipients' names. AddEmail will create Unicode e-mail (UTF-8 encoding) if any part of the message contains Unicode characters.

This method is synchronous: it returns after the message was sent or after an error occuried. Please use it with care because single-threaded applications are blocked and can't process user input for the duration of the SimpleSendAttachment call. Please refer to SendAsync Method if you want to send messages without blocking your application.