Skip to main content

Open Outlook with Attachment

  • April 9, 2013
  • 9 replies
  • 0 views

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

9 replies

Chris Glazier
Forum|alt.badge.img+2

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

If you are referring to sending an e-mail with an attachment from Outlook, the following example will do that:

     $set ilusing"System.Net.Mail"
     $set ilusing"System.Net"
     $set ilusing"Microsoft.Office.Interop.Outlook"
      program-id. Program1 as "testemail.Program1".
      data division.
      working-storage section.
      01 oApp type Microsoft.Office.Interop.Outlook.ApplicationClass.
      01 omsg type Microsoft.Office.Interop.Outlook.MailItem.
      01 oAttach type Microsoft.Office.Interop.Outlook.Attachment.
      01 oRecips type Microsoft.Office.Interop.Outlook.Recipients.
      01 oRecip type Microsoft.Office.Interop.Outlook.Recipient.
      01 sDisplayName string.
      01 iPosition binary-long.
      01 iAttachType binary-long.
      procedure division.

          try
       *> Create the Outlook application.
             set oApp to new type Microsoft.Office.Interop.Outlook.ApplicationClass
       *> Create a new mail item.
             set oMsg to oApp::CreateItem(type
                Microsoft.Office.Interop.Outlook.OlItemType::olMailItem) as type Microsoft.Office.Interop.Outlook.MailItem
       *> Set HTMLBody.
       *> add the body of the email
             set oMsg::HTMLBody to "Hello, your message body will go here!!"
       *> Add an attachment.
             set sDisplayName to "MyAttachment"
             set iPosition to oMsg::Body::Length 1
             set iAttachType to type Microsoft.Office.Interop.Outlook.OlAttachmentType::olByValue
                as binary-long
       *> now attach the file
             set oAttach to oMsg::Attachments::Add("C:\\\\temp\\\\testfile.txt", iAttachType, iPosition, sDisplayName)
       *> Subject line
             set oMsg::Subject to "Your Subject will go here."
       *> Add a recipient.
             set oRecips to oMsg::Recipients
       *> Change the recipient in the next line if necessary.
             set oRecip to oRecips::Add(chris.glazier@microfocus.com)
             invoke oRecip::Resolve
       *> Send.
             invoke oMsg::Send
       *> Clean up.
             set oRecip to null
             set oRecips to null
             set oMsg to null
             set oApp to null
          catch ex as type System.Exception
             display ex::Message
          end-try
          goback.
      end program Program1.


Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Hi Chris,

Thanks for that, a couple of questions?

1) Will this work with any version of outlook a client has installed on their pc?

2) Does this code open Outlook, create email, send email, then close Outlook, all automatically?

Many thanks

Neil.


Chris Glazier
Forum|alt.badge.img+2

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

This sample uses the .NET Framework classes in microsoft.office.interop.outlook assembly.

You would need to add a reference to this assembly in your project.

This is documented as being supported for Outlook 2007 and 2010 and on my system I tested with Outlook 2010.

This uses the Outlook COM Server so Outlook does not have to be up and running in order for this to work.

The only suggestion that I can make is for you to test it on the required target systems to ensure compatibility with all.

Thanks.


Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Thanks Chris, is this project/code available to download any where?


Chris Glazier
Forum|alt.badge.img+2

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

I have just attached it here.

Please download emailwithattach.zip.

 


Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Hello Chris, good morning, God bless you for your courageous collaboration with the issue of separation in columns of excel, as you can see I could enable my id in the community.
I am trying the code that you attached and I managed to implement it in my project, you know or know a way to apply the values ​​of my POP3 server and SMTP for user and password

Chris Glazier
Forum|alt.badge.img+2

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Hi Edwin,

There is a property called account which contains some fields that can be set including the smtp server name which can be found here but this example is for use with managed .NET COBOL as it references a .NET class. If you are using native COBOL then this will not work. Are you using native or managed .NET code?


Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Hello Chris

I can not use Outlook from native cobol, I saw that it was simpler and faster using Cobol .net. The main program is built in native cobol, so I will have to make a call to the routine that will send the email from said code, sending the parameters of body, recipients and subject. The e-mail account that you must use to send e-mail has user password an SMTP and POP3 configuration


Thank you for your valuable help.

Hi,

Does anyone know how to open Outlook with an attachment from Visual Cobol.

This would have to work with all the "different" versions of Outlook 2007, 2010 etc etc without any program changes.

Thanks

Neil.

Chris, good day
I try to configure POP3 and SMTP, in the documentation they speak that the instruction only returns values ​​does not allow the direct configuration of parameters, you have some guide on which I can base to make said configuration