Skip to main content

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

It is pretty straight forward using our .Net support, the URL below shows how to do it in C#, for simplicity I uses the library from code.msdn.microsoft.com/CSharpGmail

The COBOL code equivalent of their example is:

      $set ilusing"System.Web.Mail"
      $set ilusing"GmailHelper"
       program-id. Program1 as "ConsoleApplication1.Program1".

       data division.
       working-storage section.
       *>Use the GmailMessage object to create and send your message
       01 gmailMsg             type RC.Gmail.GmailMessage.
       01 attachment           type MailAttachment.
       01 mailMessageObject    type MailMessage.

       procedure division.
           *> Send a message with one line of code
           invoke type RC.Gmail.GmailMessage::SendFromGmail("username", "password", "toAddress@gmail.com", "subject", "message body")


           *> Send a message with one line of code with a MailMessage object
           invoke type RC.Gmail.GmailMessage::SendMailMessageFromGmail("username", "password", mailMessageObject)


           set gmailMsg to new type RC.Gmail.GmailMessage("username", "password")
           set gmailMsg::To to "RCcode@gmail.com"
           set gmailMsg::From to "fromAddress@gmail.com"
           set gmailMsg::Subject to "C# Test Message"
           set gmailMsg::Body to "Test body"

           set attachment to new type System.Web.Mail.MailAttachment("c:\\testfile.txt")
           invoke gmailMsg::Attachments::Add(attachment)

           invoke gmailMsg::Send()
           goback.
           
       end program Program1.

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

In Visual COBOL managed code using .NET framework classes:

      $set ilusing"System.Net"
      $set ilusing"System.Net.Mail"
       program-id. SendMailCobol as "SendMailCobol".

       data division.
       working-storage section.
       01 mailaddr      Type MailAddress.
       01 mailmsg       Type MailMessage.
       01 client        Type SmtpClient.

       procedure division.
           set mailmsg to new MailMessage()
           set mailaddr to new MailAddress("somename@domain.com", "John Doe")
           invoke mailmsg::To::Add(mailaddr)
           
           set mailmsg::From to new MailAddress("youremail@gmail.com", "Your Name")
           set mailmsg::Subject to "Sent from Visual COBOL"
           set mailmsg::Body to "Your Message Text"
           set mailmsg::IsBodyHtml to false

       *> Add an attachment to the Attachments collection of the mail message object
           invoke mailmsg::Attachments::Add(new Attachment("C:\\yourfile.pdf"))
           
           set client to new SmtpClient()
           set client::Credentials to new NetworkCredential("youremail@gmail.com", "yourpassword")
           set client::Port to 587
           set client::Host to "smtp.gmail.com"
           set client::EnableSsl to true
           try
               invoke client::Send(mailmsg)
           catch
               display exception-object::Message
           end-try
           goback.

       end program SendMailCobol.


Make sure you have a gmail account established if going thru the gmail smtp server. If using another smtp server, then you would need to change the host, port, and EnableSSL properties accordingly. If you need to add more than one attachment then call the Add method for each attachment.

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

PattyStep,

while these fine examples are using Visual COBOL, I suppose you are looking for one using Extend? Try to do the translation, if you get stuck, post your work here and we can see if we can work this out together.

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

Can i take the same result without using any .Net or google object?

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

Hi, dear.
I need to compile this program in AcuCobol, can you help-me

[Migrated content. Thread originally posted on 07 February 2011]

Has anyone accomplished creating a program that will generate an email with an attachement using GMAIL from a cobol progarm? If so, are you willing to share your code. I presently have a program that uses windows email. We pass the email address and attachment path and the program creates an email with the attachment and calls microsoft email and sends the message. We want to do the same with GMAIL.

Take a look at: community.microfocus.com/.../sending-email-using-gmail-and-other-newer-protocols