Skip to main content

Send email from cobol native with SMTP parameters

  • June 2, 2017
  • 16 replies
  • 0 views

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

16 replies

Chris Glazier
Forum|alt.badge.img+2

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
It looks like this can be done using the SmtpClient class in managed code. It would be possible to create a .NET program that uses this class and then call this from native code.

msdn.microsoft.com/.../system.net.mail.smtpclient(v=vs.110).aspx

Lanter Werner
  • Participating Frequently
  • June 3, 2017

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Have a look to www.marshallsoft.com.

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

I think I used marshallsoft from an mf cobol program over 15 years ago to mass send email for an email news service. Worked very well.
NEXT QUESTION... how to create PDFs and attach them too?
It would be great to be able to create PDFs and send an email (to invoice clients etc) all from a visual cobol app.
Thanks,
Linden


Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

I think I used marshallsoft from an mf cobol program over 15 years ago to mass send email for an email news service. Worked very well.
NEXT QUESTION... how to create PDFs and attach them too?
It would be great to be able to create PDFs and send an email (to invoice clients etc) all from a visual cobol app.
Thanks,
Linden


Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
The entire platform of files and tables is on a server with Windos Server 2012r2 through cobol server 2.3. Perform tests with MarshallSoft, but for the most part, the process stops when it is run, and send a ticket to the developer without answer. COBEMAIL has not worked, the only way I have is to make a code through which I can send an email confirmation of a transaction, attaching a .txt with the information of the transaction made. But I must use the SMTP and POP mail server, not do it through an API that controls Outlook.
God bless you, thank you very much for your interest in this subject

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Sending email via native COBOL can be done using the CDO libraries from Microsof (I think you can still use these).

This is relatively easy to convert to COBOL.

Just remember to create an exception handler as well as a local working storage section to manage the exceptions

The code below is just VB script. Perhaps download the CDO library, modify the VB script first to get it working, then convert to COBOL. If this is an in-house solution. If you are sending via Exchange server you must give permissions to enable SMTP.

msdn.microsoft.com/.../ms526130(v=exchg.10).aspx


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Test SMTP FROM MANDY- Please confirm i f you receive this message"

objMessage.Sender = "MANDY@xyz.com"

objMessage.To = "Fred@aaa.com"

objMessage.TextBody = "Cool. Please email me if you received this message, thanks"

objMessage.Configuration.Fields.Item _
("schemas.microsoft.com/.../sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("schemas.microsoft.com/.../smtpserver") = "192.168.1.55"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("schemas.microsoft.com/.../smtpserverport") = 25


'SMTP authenticate
'objMessage.Configuration.Fields.Item _
'("schemas.microsoft.com/.../smtpauthenticate") = 1

'SMTP UserName
objMessage.Configuration.Fields.Item _
("schemas.microsoft.com/.../sendusername") = "mydomain\\Mandy"

'SMTP Password
objMessage.Configuration.Fields.Item _
("schemas.microsoft.com/.../sendpassword") = "mypassword"


objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==

objMessage.Send
Msgbox("Done")

This might work for you.

Neil

Chris Glazier
Forum|alt.badge.img+2

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

The following is an example of sending an email with an attachment using the .NET SmtpClient class. This allows you to specify the host name and port to use as well as many other properties. This example uses an async send method.

 

 
      $set ilusing"System.Net"
      $set ilusing"System.Net.Mail"
      $set ilusing"System.Net.Mime"
      $set ilusing"System.Threading"
      $set ilusing"System.ComponentModel"

       class-id sendsmtpmail.SimpleAsynchronousExample.

       working-storage section.
       01 mailSent condition-value static value false.

       method-id SendCompletedCallback static private (sender as object, e as type AsyncCompletedEventArgs).
           *> Get the unique identifier for this asynchronous operation.
           declare token as string = e::UserState as string

           if e::Cancelled
              invoke type Console::WriteLine("[{0}] Send canceled.", token)
           end-if
           if e::Error not = null
              invoke type Console::WriteLine("[{0}] {1}", token, e::Error::ToString())
           else
              invoke type Console::WriteLine("Message sent.")
           end-if
           set mailSent to true
           goback.
       end method.
       method-id Main public static (args as string occurs any)
.          *> The SMTP host name is passed as a string in the constructor in this example
           declare client as type SmtpClient = new SmtpClient("mail.myserver.com")
           *> Specify the e-mail sender.
           *> Create a mailing address
           declare #from as type MailAddress = new MailAddress("chris.glazier@microfocus.com", 
               "Chris Glazier", type System.Text.Encoding::UTF8)
           *> Set destinations for the e-mail message.
           declare #to as type MailAddress = new MailAddress("chris.glazier@microfocus.com")
           *> Specify the message content.
           declare #message as type MailMessage = new MailMessage(#from, #to)
           set #message::Body = "This is a test e-mail message sent by an application. " 
              & type Environment::NewLine
           set #message::BodyEncoding =  type System.Text.Encoding::UTF8
           set #message::Subject = "test message 1"
           set #message::SubjectEncoding = type System.Text.Encoding::UTF8
           *> Set the method that is called back when the send operation ends.
           
           invoke #message::Attachments::Add(new Attachment("C:\\temp\\testfile.txt"))
            attach method self::SendCompletedCallback to client::SendCompleted
           
           *> The userState can be any object that allows your callback 
           *> method to identify this send operation.
           *> For this example, the userToken is a string constant.
           declare userState as  string = "test message1"
           set client::Credentials = type CredentialCache::DefaultNetworkCredentials
           invoke client::SendAsync(#message, userState)
           invoke type Console::WriteLine("Sending message... press c to cancel mail. Press any other key to exit.")
           declare answer as string = type Console::ReadLine
           *>  If the user canceled the send, and mail hasn't been sent yet,
           *>  then cancel the pending operation.
           if answer::StartsWith("c") and mailSent = false
              invoke client::SendAsyncCancel
           end-if
           *> Clean up.
           invoke #message::Dispose
           invoke type Console::WriteLine("Goodbye.")

           goback.
       end method.
           
       end class.

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Hello Chris Good day, I am testing your solution, but I generate errors in the definition, I am running under net framework 4.6, I am not clear if I am using a wrong version of netframework, muchas gracias Chris 

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Hello Chris Good day, I am testing your solution, but I generate errors in the definition, I am running under net framework 4.6, I am not clear if I am using a wrong version of netframework, muchas gracias Chris 

Chris Glazier
Forum|alt.badge.img+2

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Sorry, you would need to add a reference to the System.Net assembly in your project in order to access the classes.

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Hi chris, sorry for the inconvenience, modify what you need. But I still do not get the receipt of the email generated in the code, and validate that the email account and everything is fine




$set ilusing"System.Net"
$set ilusing"System.Net.Mail"
$set ilusing"System.Net.Mime"
$set ilusing"System.Threading"
$set ilusing"System.ComponentModel"

class-id sendsmtpmail.SimpleAsynchronousExample.

working-storage section.
01 mailSent condition-value static value false.


procedure division.
method-id Main public static (args as string occurs any).
. *> The SMTP host name is passed as a string in the constructor in this example
declare client as type SmtpClient = new SmtpClient("smtp.croydon.com.co")
*> Specify the e-mail sender.
*> Create a mailing address
declare #from as type MailAddress = new MailAddress("sistemaaurora@croydon.com.co",
"Chris Glazier", type System.Text.Encoding::UTF8)
*> Set destinations for the e-mail message.
declare #to as type MailAddress = new MailAddress("soporte_sistemas@crydon.com.co")
*> Specify the message content.
declare #message as type MailMessage = new MailMessage(#from, #to)
set #message::Body = "Prueba de correo electronico utilizando servidor SMTP"
& type Environment::NewLine
set #message::BodyEncoding = type System.Text.Encoding::UTF8
set #message::Subject = "Prueba SMTP"
set #message::SubjectEncoding = type System.Text.Encoding::UTF8
*> Set the method that is called back when the send operation ends.

invoke #message::Attachments::Add(new Attachment("C:\\temp\\testfile.txt"))
* attach method self::SendCompletedCallback to client::SendCompleted

*> The userState can be any object that allows your callback
*> method to identify this send operation.
*> For this example, the userToken is a string constant.
declare userState as string = "test message1"
set client::Credentials = new NetworkCredential("sistemaaurora@croydon.com.co", "**********")
invoke client::SendAsync(#message, userState)
invoke type Console::WriteLine("Enviando correo, press C para cancelar")
declare answer as string = type Console::ReadLine
*> If the user canceled the send, and mail hasn't been sent yet,
*> then cancel the pending operation.
if answer::StartsWith("c") and mailSent = false
invoke client::SendAsyncCancel
end-if
*> Clean up.
invoke #message::Dispose
invoke type Console::WriteLine("Goodbye.")

goback.
end method.

Chris Glazier
Forum|alt.badge.img+2

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Is this a typo? should crydon be Croydon?
MailAddress("soporte_sistemas@crydon.com.co")

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching
Sorry Chris, when copying and editing the text erase without intention, and check in my code and I do not have that error

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

good day Get the sending of emails from the SMTP server using code in managed cobol. How can I make the call of said code from a code in native cobol from which I will send the recipients, subject and content of the electronic mail. As the link area used in native cobol, thanks and blessings for your valuable collaboration

this is the code in cobol menaged

 

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


data division.
working-storage section.
01 DIRECCION TYPE MailAddress.
01 MAILCOPY TYPE MailAddressCollection.
01 MENSAJE TYPE MailMessage.
01 CUENTA TYPE SmtpClient.

77 CONCOPIA PIC X(55) VALUE "soporte_sistemas@croydon.com.co; mgalvis@croydon.com.co".
77 DESTINATARIOS PIC x(31) VALUE "soporte_sistemas@croydon.com.co".
77 CONTENIDO PIC x(300) VALUE "mensaje de correo electronico enviado desde el sistema AURORA. Por favor no responder a este mensaje".
77 TITULO PIC x(100) VALUE "Prueba de envio de correo electronico AURORA".


procedure division.
*> CREA MENSAJE Y ALISTA LA COLA DE ENVIO
SET MENSAJE TO NEW MailMessage()
SET DIRECCION TO NEW MailAddress(DESTINATARIOS)
SET MAILCOPY TO NEW MailAddressCollection()
INVOKE MENSAJE::To::Add(DIRECCION)


*> CREA CONTENIDO, REMITENTE, Y ASUNTO DEL EMAIL
SET MENSAJE::From to new MailAddress("sistemaaurora@croydon.com.co", "Sistema AURORA")
SET MENSAJE::Subject to TITULO
SET MENSAJE::Body to CONTENIDO
SET MENSAJE::IsBodyHtml to false

*> ARCHIVO ADJUNTO PARA ENVIO
INVOKE MENSAJE::Attachments::Add(NEW Attachment("F:\\prueba\\attach.jpg"))
*> CONFIGURACION DE LA CUENTA Y CREDENCIALES
SET CUENTA TO NEW SmtpClient()
SET CUENTA::Credentials TO NEW NetworkCredential("sistemaaurora@croydon.com.co", "********")
SET CUENTA::Port TO 25
SET CUENTA::Host TO "smtp.croydon.com.co"
SET CUENTA::EnableSsl TO FALSE
TRY
INVOKE CUENTA::Send(MENSAJE)
CATCH
DISPLAY exception-object::Message
END-TRY
GOBACK.
END PROGRAM SendMailCobol.


Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

good day Get the sending of emails from the SMTP server using code in managed cobol. How can I make the call of said code from a code in native cobol from which I will send the recipients, subject and content of the electronic mail. As the link area used in native cobol, thanks and blessings for your valuable collaboration

this is the code in cobol menaged

 

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


data division.
working-storage section.
01 DIRECCION TYPE MailAddress.
01 MAILCOPY TYPE MailAddressCollection.
01 MENSAJE TYPE MailMessage.
01 CUENTA TYPE SmtpClient.

77 CONCOPIA PIC X(55) VALUE "soporte_sistemas@croydon.com.co; mgalvis@croydon.com.co".
77 DESTINATARIOS PIC x(31) VALUE "soporte_sistemas@croydon.com.co".
77 CONTENIDO PIC x(300) VALUE "mensaje de correo electronico enviado desde el sistema AURORA. Por favor no responder a este mensaje".
77 TITULO PIC x(100) VALUE "Prueba de envio de correo electronico AURORA".


procedure division.
*> CREA MENSAJE Y ALISTA LA COLA DE ENVIO
SET MENSAJE TO NEW MailMessage()
SET DIRECCION TO NEW MailAddress(DESTINATARIOS)
SET MAILCOPY TO NEW MailAddressCollection()
INVOKE MENSAJE::To::Add(DIRECCION)


*> CREA CONTENIDO, REMITENTE, Y ASUNTO DEL EMAIL
SET MENSAJE::From to new MailAddress("sistemaaurora@croydon.com.co", "Sistema AURORA")
SET MENSAJE::Subject to TITULO
SET MENSAJE::Body to CONTENIDO
SET MENSAJE::IsBodyHtml to false

*> ARCHIVO ADJUNTO PARA ENVIO
INVOKE MENSAJE::Attachments::Add(NEW Attachment("F:\\prueba\\attach.jpg"))
*> CONFIGURACION DE LA CUENTA Y CREDENCIALES
SET CUENTA TO NEW SmtpClient()
SET CUENTA::Credentials TO NEW NetworkCredential("sistemaaurora@croydon.com.co", "********")
SET CUENTA::Port TO 25
SET CUENTA::Host TO "smtp.croydon.com.co"
SET CUENTA::EnableSsl TO FALSE
TRY
INVOKE CUENTA::Send(MENSAJE)
CATCH
DISPLAY exception-object::Message
END-TRY
GOBACK.
END PROGRAM SendMailCobol.


Chris Glazier
Forum|alt.badge.img+2

Good day please someone has knowledge or has an example of sending email by defining an SMTP server and attaching a file native Cobol, Many thanks for your collaboration


#VisualCOBOL
#nativecobol
#Email
#COBOL
#attaching

You would need to compile your managed code as a class and register for use as a COM server. You would either modify your program to use class and methods instead of program-id or create a class wrapper and CALL your existing program from within it.

Take a look at the article here: