Send email from cobol native with SMTP parameters

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

Ojala.ZIP
  • 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
  • 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

  • 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

  • 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
  • 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
  • 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.
    
  • 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  
  • 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  
  • Sorry, you would need to add a reference to the System.Net assembly in your project in order to access the classes.