AddMemoryAttachment Method


Creates an attachment from binary block of memory and attaches it to the message.

Attached files are automatically base64-encoded to comply with MIME requirements. This method can also handle inline objects (such as images) related in message body.


[Visual Basic]

blnResult = ObjectName.AddMemoryAttachment(Data, FilenameInMessage, [ContentType], [ContentID])

 
Parameters:  
Data As Variant Attachment binary data represented as Byte Array.  
FilenameInMessage As String It will be used in the message as attachment filename. For instance, the developer has a disk file C:\Data\abc.tmp and he is going to add this file to the message as a graph.gif file . To do this, he should set FilenameInMessage="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) If you already know Content-Type of the file, you may specify it. If this parameter is omitted, Content-Type is taken from the filename extension.  
ContentID As String (optional) Non-empty value denotes that the file is related in message 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 is ASP-only sample which attaches last uploaded file to the message without creating any temporary files

Dim Mailer, Uploader, File

' Create new objects
Set Mailer = Server.CreateObject("MailBee.SMTP")
Set Uploader = Server.CreateObject("MailBee.Uploader")

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

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

' Try to connect to the specified mail server
If Mailer.Connect Then

  ' Specify the e-mail address of the message recipient
  Mailer.Message.ToAddr = "bill@yoursite.com"

  ' Specify the e-mail address of the message sender
  Mailer.Message.FromAddr = "joe@mysite.com"

  ' Specify the subject of the message
  Mailer.Message.Subject = "Hello"

  ' Import the text of the message body from file
  Mailer.Message.ImportBodyText "C:\docs\letter.htm", True

  ' Get the server's response as a binary array
  Uploader.ParseRequest(Request.BinaryRead(Request.TotalBytes))

  ' Check if the form contains any files
  If (Uploader.FormFiles.Count <> 0) Then
	   ' Select the last file related to the form
	   Set File = Uploader.FormFiles(Uploader.FormFiles.Count)

	   ' Add attachment under the name of selected file
	   Mailer.Message.AddMemoryAttachment File.ValueAsArray, File.FileName
  End If

  ' Send the message
  Mailer.Send

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

See Also:

AddAttachment Method, Uploader Object


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