Skip to main content

[archive] Adding Attachments to Email using OSSMTP32 ActiveX Control

  • July 27, 2010
  • 10 replies
  • 1 view

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.

10 replies

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
It might go quicker if yu post the def file.

http://www.acucorp.com/support/suppo...read.php?t=297
Here's what we're using.
Hopefully this helps.

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
Thanks, Dilbert, but when I click on that link, it tells me the webpage cannot be found.

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
Here is the DEF file that I am using.

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
What happens when you use this property?

PROPERTY-PUT, 1745027074, @AttachmentName,

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
When i use ActiveX DEF Utility i see that smtp has


the property @Attachments which is a Collection
so i think that i must define each file for the collection.


so i see in the Overview of the Utility that a class is defined @Attachment
with several property's.
- @AttachmentName
- @ContentTransferEncoding
- @ContentType
- @FilePath


my theory is you have to create a handle for the attachment and then put this handle to the Attachments Collection...

for Example:

- PART 1 -
77 h-attachment handle of @Attachment.
77 w-var-filepath pic x(256)

move "..." to w-var-filepath.
inspect w-var-filepath replacing trailing spaces by low-value.

modify h-attachment @FilePath = w-var-filepath.



- PART 2 -

77 h-smtp handle of @SMTP
77 w-var-attachments handle.

here my theory is that you have to inquire first the attachments to have the handle for it.

inquire h-smtp Attachments w-var-attachments.

than you can put the files in it.
modify w-var-attachments::Add h-attachment.



this is only my theory...


with google you can find this description for the attachments part:

Attachments collection
contains message attachments

Supports following methods:

collection.Add oAttachment, [oAttachment_ID]
adds new Attachment object ([oAttachment_ID] - optional attachment ID)

collection.Remove object.Attachments(oAttachment_ID)
removes specified Attachment object (oAttachment_ID - attachment ID or Index)

collection.Count
returns number of attachments

collection(oAttachment_ID)
returns specified Attachment object (oAttachment_ID - attachment ID or Index)


Attachment object

object.AttachmentName As String
Attachment name (optional, default - file name from file path)

object.ContentTransferEncoding
Content-transfer-encoding of attachment (optional, default - base 64)

object.ContentType As String
Content-type of attachment (optional, default - Registry setting corresponding to file extension)

object.FilePath As String
Location of attachment source

David

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
I still cannot get it to work.:(

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
Here is a VB-Script example i found:


Option Explicit

Dim oSMTP 'As OSSMTP_Plus.SMTPSession
Dim sStatus 'As String
Dim bClose 'As Boolean
Dim nTimeout 'As Long
Dim n 'As Long

sStatus = ""
bClose = False
nTimeout = 1000
n = 0

Set oSMTP = CreateObject("OSSMTP_Plus.SMTPSession")
WScript.ConnectObject oSMTP, "oSMTP_"

oSMTP.Server = "localhost" 'server name or IP address
oSMTP.MailFrom = "info" 'sender e-mail address
oSMTP.SendTo = "test" 'recipient e-mail address
oSMTP.MessageSubject = "test message" 'message subject
oSMTP.MessageText = "this is " & vbCrLf & "multi-line test" 'message text
oSMTP.MessageHTML = "this is " & vbCrLf & "multi-line test" 'message text
oSMTP.RaiseError = True

''optional properties (uncomment as needed)
''connection
'oSMTP.Port = 25 'only needed for non-standard mailserver port
'oSMTP.ClientHostName = "myHomePC"
'oSMTP.Timeout = 1000 'ms
''authentication
'oSMTP.AuthenticationType = 2 '1 - POP3, 2 - AUTH LOGIN, 3 - AUTH PLAIN
'oSMTP.Username = "login"
'oSMTP.Password = "password"
'oSMTP.POPServer = "pop3server" 'for POP3 authentication only
'oSMTP.UseSSL = True 'for mailservers requiring secure session
''extra headers
'oSMTP.ExpiresAfter = "2/2/2020"
'oSMTP.Importance = 0 '0 - normal, 1 - low, 2 - high
'oSMTP.Notification = 0 '0 - none, 1 - on delivery, 2 - on read, 3 - on both
'oSMTP.ReplyTo = "not_me@someserver.com"
'oSMTP.Sensitivity = 0 '0 - normal, 1 - personal, 2 - private, 3 - confidential
'oSMTP.TimeStamp = "1/1/1979" 'instead of current time
''recipients
'oSMTP.BCC = "one, two, three"
'oSMTP.CC = "some_address"
''message
'oSMTP.Charset = "KOI8-R"
'oSMTP.ContentTransferEncoding = "base64"
'oSMTP.ContentType = "text/plain"

'custom header
Dim c 'As OSSMTP_Plus.CustomHeader
Set c = CreateObject("OSSMTP_Plus.CustomHeader")
c.HeaderName = "x-test"
c.HeaderValue = "test header"
oSMTP.CustomHeaders.Add c

'attachment
Dim a 'As OSSMTP_Plus.Attachment
Set a = CreateObject("OSSMTP_Plus.Attachment")
a.FilePath = "c:\\boot.ini"
'uncomment to over-write default (file name)
'a.AttachmentName = "test attachment"
'uncomment to over-write default (corresponding content type from registry)
'a.ContentType = "application/octet-stream"
'uncomment to over-write default (Base64)
'a.ContentTransferEncoding = 2 '1 - enc7Bit, 2 - encBase64)
oSMTP.Attachments.Add a

'embedded image
Dim e 'As OSSMTP_Plus.EmbeddedObject
Set e = CreateObject("OSSMTP_Plus.EmbeddedObject")
e.FilePath = "c:\\windows\\system32\\ntimage.gif"
e.ObjectID = "image01"
oSMTP.EmbeddedObjects.Add e

oSMTP.SendEmail

Sub oSMTP_ConnectSMTP()
'connected to mailserver
End Sub

Sub oSMTP_SendSMTP()
'message successfully sent
End Sub

Sub oSMTP_StatusChanged(ByVal Status)
  sStatus = sStatus & Status & vbCrLf
End Sub

Sub oSMTP_ErrorSMTP(ByVal Number, Description)
'error occured
  sStatus = sStatus & "Error " & Number & ": " & Description & vbCrLf
  bClose = True
End Sub

Sub oSMTP_CloseSMTP()
'connection to mailserver closed
  bClose = True
End Sub

Do While Not bClose
  WScript.Sleep 1
  n = n 1
  If n > nTimeout Then
    sStatus = sStatus & "Timeout" & vbCrLf
    Exit Do
  End If
Loop

WScript.Echo sStatus
Set oSMTP = Nothing


i hope this helps you

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
Thanks, but I don't understand VB and how to covert that code to Cobol Code in order for it to work in my program.

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
and using "add" will not work. The program will not compile because "add" is not a defined data item. "attachment" and "attachments" are not defined data items. I am just at a total loss as to how to get this to work.

[Migrated content. Thread originally posted on 27 July 2010]

Hello,

I am trying to figure out how to attach a file to an email that is being send from my software product and could use some assistance.

In WORKING-STORAGE, the EMAIL-HANDLE is defined with a USAGE HANDLE OF SMTP.

Within code I have code like the following

MODIFY EMAIL-HANDLE
@Server = EMS-SERVER
@MailFrom = TCS-FROM-ADDR
@SendTo = WS-TO-EMAIL
@MessageSubject = TCS-SUBJECT
@MessageText = TEST-MESSAGE

then further down in the code, I have

MODIFY EMAIL-HANDLE
@RaiseError(0)
@SendEmail().


What I need to figure out is how to add an attachment (like a pdf report) to the email, that I am sending out. No matter what I do, I cannot for the life of me figure out how to send an email with an attachment.

If I could get some help to figure this out, my customers would be so happy, which would make my bosses happy :D


Thank you.
Try this:
77 h-attachment handle of @Attachment

Create Attachment Handle in h-attachment.
Modify h-attachment filepath = "c:\\myfile.pdf".
Modify h-attachment AttachmentName = "Annual report".
Modify h-attachment ContentType = "application/octet-stream".
Modify email-handle Attachments::Add(h-attachment).

Note that you never need to use trailing low-values in conjunction with ActiveX/COM