Hello,
I have created an email.dll in C# to send email within a powerbuilder program.
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
using System.Net.Mail;
namespace seguindev
{
public class Mail
{
public int SendEmail(string strFrom, string strTo, string strSubject, string strBody, string strHost, int intPort)
{
int li_status = 1;
MailMessage mail = new MailMessage();
mail.To.Add(strTo);
mail.From = new MailAddress(strFrom);
mail.Subject = strSubject;
mail.Body = strBody;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = strHost;
smtp.Port = intPort;
smtp.UseDefaultCredentials = true;
smtp.EnableSsl = true;
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
return li_status;
}
}
}
Powerbuilder function calling the C# function:
// function of_afterSaveActivity
// parameter: current master row = ai_row
int li_status
nvo_mail mail
mail = create nvo_mail
li_status = mail.of_sendemail("daniel@seguin.dev","danieloseguin67@gmail.com","This is a test", "This is the body of the email","smtp.gmail.com",587)
if li_status = 1 then
MessageBox("Message","Message was sent successfully")
else
MessageBox("Message","Message was NOT sent successfully")
end if
//*-----------------------------------------------------------------*/
//* .NET function : SendEmail
//* Argument:
//* String as_strfrom
//* String as_strto
//* String as_strsubject
//* String as_strbody
//* String as_strhost
//* Long al_intport
//* Return : Long
//*-----------------------------------------------------------------*/
/* Store the Return value from dotnet function */
Long ll_result
/* Create .NET object */
If Not This.of_createOnDemand( ) Then
SetNull(ll_result)
Return ll_result
End If
/* Trigger the dotnet function */
ll_result = This.sendemail(as_strfrom,as_strto,as_strsubject,as_strbody,as_strhost,al_intport)
Return ll_result
Here is the import of dll:
Any ideas?
Thanks
Daniel