Skip to content

Instantly share code, notes, and snippets.

@TristanOrta
Last active July 1, 2022 03:37
Show Gist options
  • Save TristanOrta/b152958e73e922f5dd69290c28eed05d to your computer and use it in GitHub Desktop.
Save TristanOrta/b152958e73e922f5dd69290c28eed05d to your computer and use it in GitHub Desktop.
Implementation of pbni smtp for sending emails with Powerbuilder /implementacion de pbni smtp para envio de correos con powerbuilder
integer li_rc
string ls_sender
n_cpp_smtp l_smtp
String connectiontype, currentdirectory
ChangeDirectory ( currentdirectory )
TRY
SetPointer ( HourGlass! )
//Create the object
l_smtp = CREATE n_cpp_smtp
ls_sender = 'SenderMail' + ' <[email protected] >'
l_smtp.SetUserNamePassWord ( 'User', 'Pass' )
l_smtp.SetRecipientEmail (ls_recipient)
l_smtp.SetSenderEmail (ls_sender)
l_smtp.SetSubject (ls_subject)
l_smtp.SetMessage (ls_message, TRUE)
l_smtp.SetSMTPServer ('smtp.gmail.com')
l_smtp.SetCharSet ('iso-3356-3')
l_smtp.SetAttachment ( ls_attach )
l_smtp.setconnectiontype ( 2 ) // connection type 2 refers to the TLS protocol if you want to use the SSL protocol assign value 1
//Send the email
l_smtp.seterrormessageson()
li_rc = l_smtp.Send ( )
//Let the user know it worked
IF li_rc = 1 THEN
MessageBox ('Message' , "Message Sent" )
ELSE
MessageBox ( 'Message', "Error: " + String ( li_rc ) )
END IF
CATCH ( NullObjectError noe )
MessageBox( "Null Object Exception", noe.getMessage() )
CATCH ( PBXRuntimeError pbxre )
MessageBox( "PBX Exception", pbxre.getMessage() )
CATCH ( Throwable oe )
MessageBox( "Other Exception", oe.getMessage() )
FINALLY
Destroy ( l_smtp )
END TRY
Return
// call the function "f_envia_smtp_pbni" with the following parameters
string ls_recipient = 'Oscar Tristan <[email protected]>'
string ls_subject = 'This is a message sent from PBNI'
string ls_message = 'Hello, I sent this message from PB'
string ls_attach = 'My file path'
f_envia_smtp_pbni(ls_recipient,ls_subject,ls_message,ls_attach)
//This module is an adaptation of the "PBNISMTP" library which is a PBNI (PowerBuilder Native Interface) developed by Bruce Armstrong, and improved by Roland Smith
//This function sends emails by smtp from Gmail
//We must download the file Download PBNISMTP from https://www.topwizprogramming.com/pbnismtp.html
//in our project select the library where we will create the mailing function
//We will right click on the library and select "Import PB Extension" and add the .PBX file that we downloaded from
//https://www.topwizprogramming.com/pbnismtp.html
//Append the .PBL, .PBT, PBX files to the project folder
// this was tested on pb2021 and windows 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment