AddStringAttachment Method


Creates an attachment from text string by converting data string to bytes and attaches it to the message.

After that, attached files are automatically encoded to base64 encoding to comply with MIME requirements. This method can also handle inline objects (such as images) related to the message body.

Because attachments are binary files (series of 8-bit bytes) while strings are series of 16-bit wide chars, MailBee needs to know how to convert wide chars of the source string into bytes of the attachment data. AsUTF8 parameter controls this.

Nevertheless, base64 encoding is still applied after string-to-bytes conversion, no matter what value AsUTF8 is.


blnResult = ObjectName.AddStringAttachment(Data, AsUTF8, FilenameInMessage, [ContentType], [ContentID])  
Parameters:  
Data As String Attachment text data represented as String.  
AsUTF8 As Boolean If True, will convert the source string into UTF-8 bytes. Otherwise, will use the default system encoding for conversion.  
FilenameInMessage As String Specifies the file name of the attachment in message. For example, if you have file "C:\Data\abc.tmp" and want to add it to the message as file "graph.gif", you just need to specify FilenameInMessage as "graph.gif". If FilenameInMessage="<none>" (angle brackets are important), no filename will be assigned at all (useful when forwarding e-mail messages as attachment).  
ContentType As String (optional) Specifies the Content-Type of file if it's already known. If this parameter is empty or ommited, Content-Type is taken from filename extension.  
ContentID As String (optional) Non-empty value denotes that the file is related tomessage body with specified Content-ID (i.e. inline object). Omitted or empty value denotes ordinary attachment (not inline object). Inline objects are usually not displayed by email clients in attachment lists.  
Return value As Boolean True if successful, False if error has occurred  

Usage example:

<%
' This sample attaches text string as text file to the message without creating any temporary files

Dim Mailer, Uploader, File

' Using ASP to create the object
Set Mailer = Server.CreateObject("MailBee.SMTP")

' Using Visual Basic to create the object
'Set Mailer = CreateObject("MailBee.SMTP")

' Specify MailBee license key
Mailer.LicenseKey = "put your license key here"

' Specify the name of the mail server
Mailer.ServerName = "mail.server.com"

' Connect to the specified mail server
If Mailer.Connect Then
	' Load the message from file
	Mailer.Message.ImportFromFile("C:\Temp\msg.eml")

	' Add the attachment from string
	Mailer.Message.AddStringAttachment "This is attachment body", False, "sample.txt", "text/plain"

	' Send the message
	Mailer.Send

	' Disconnect from the mail server
	Mailer.Disconnect
End If
%>

See Also:

AddAttachment Method, Uploader Object


Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.