Sending emails

MiServer is Dyalog's APL-based web development framework

Re: Sending emails

Postby crishog on Wed Aug 11, 2021 9:32 pm

Brian wrote a script which sends emails. We use it in DFS. I think it us available from GIT. It works very well

I will dig out the details for you
crishog
 
Posts: 61
Joined: Mon Jan 25, 2010 9:52 am

Re: Sending emails

Postby Brian|Dyalog on Thu Aug 12, 2021 2:31 pm

Hi Jinny!

The utility that Chris is referring to is my SMTP class. It's in use in several applications including DFS, the Problem Solving Competition website, and the Dyalog User Meeting registration website. It can be found at https://github.com/Dyalog/SMTP. It's quite function and we're currently working on adding more documentation and examples and also generating "proper" releases.

For now, to use it
  • clone the repository (for this example, let's say you clone it to c:\git\SMTP)
  • since you're running MiServer, copy the files from c:\git\SMTP\APLSource\ to the Code folder of your MiSite. This will ensure that the SendMail function and SMTP class are loaded when your MiSite starts
  • now, from your application code, you can do something like (using the data from your previous example):
Code: Select all
Subj←'order'
Body←'send me 100 copies'
From←'annabelnotospam@s-k-y.com'
To←'jinnynotospam@s-k-y.com'
ServerAddr←'smtp.s-k-y.com' ⍝ you'll need to set the proper SMTP server address
(rc msg Server)←ServerAddr SendMail To Subj Body

rc is the return code, 0 indicates there was no error.
msg is a (hopefully) descriptive diagnostic message if there was an error
Server is an instance of the SMTP class that can be used to send subsequent emails.
If you look at the comments in SendMail, you'll see some examples.

I hope this helps!
/Brian
User avatar
Brian|Dyalog
 
Posts: 120
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Sending emails

Postby crishog on Fri Aug 13, 2021 2:31 pm

Got there before me Brian - and probably with better detail than I would have given.

Did you ever write a IMAP client? Just as a matter of interest
crishog
 
Posts: 61
Joined: Mon Jan 25, 2010 9:52 am

Re: Sending emails

Postby Brian|Dyalog on Fri Aug 13, 2021 4:21 pm

Hi Chris!

I have started an IMAP client utility. It needs some work yet, but it was sufficient to accomplish some tasks I had with regard to analyzing bouncebacks and replies from a bulk email transmission. The part that needs the most work is coming up with a DSL (domain specific language) that is easier to use than raw IMAP. My hope is to clean up and properly publish my IMAP, SMTP, and POP3 utilities before the end of the year.

The IMAP and POP3 classes can be found in https://github.com/Dyalog/APLToolsWIP/tree/master/mail. Once I'm happy with the level of functionality, documentation and samples, I'll move them off to their own respective repositories.

Cheers,
/Brian
User avatar
Brian|Dyalog
 
Posts: 120
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: Sending emails

Postby Jinny on Sat Aug 14, 2021 12:45 pm

Dear Chris and Brian,

Big thanks for your replies, apologies for the delay in coming back to you but it takes me a long time to (fail to) do things as I'm only a basic APL programmer - I last used it in 1992 before the internet!

I couldn't 'clone' from Github as I couldn't work out where to use the http and CLI instructions! I tried command prompt and ScriptFollows and internet with no success!

So I downloaded the zip which gave me two files (SendEmail and SMTP). Unfortunately, wherever I put them, my code doesn't seem to be able to find them. I was able to put SendEmail into my own file of utilities which solved that but can't work out what to do with SMTP. I've tried putting them into my own Code file, into Code/SMTP-main/APLSource, Code/APLSource, and MiServer-master/Utils.

This is my code (from one of the examples in SendEmail)

∇Compose;dd
:Access public
(srv←⎕NS'').(Server Port From Password)←'smtp.aol.com' 465 'blah.blah@aol.com' 'Ainny100!'
Server←3⊃srv #.hh.SendMail '' ⍝ (RUNS OK) create the server instance
(msg←⎕NS'').(To Subj Body)←'blah.blah@sky.com' 'Hello' 'If only!'
Server #.hh.SendMail msg ⍝Errors: '6 VALUE ERROR while creating client'
⍝ The server can be created and message sent in a single call:
Server←3⊃srv #.hh.SendMail msg ⍝ (RUNS OK)



And this is the point in SendEmail which appears to go wrong:
⎕NEW SMTP params


Please, what am I doing wrong?
Jinny
 
Posts: 31
Joined: Sun Jul 01, 2018 10:15 am

Re: Sending emails

Postby woody on Sat Sep 11, 2021 4:25 pm

FYI
The GITHUB location for Dyalog/SMTP tools is:

https://github.com/Dyalog/SMTP

Click on CODE button, and download the ZIP file.
Extract the two namespace files from ZIP
and place then into your MSERVER Application folder /CODE sub-folder.
You can use SALT or other methods to invoke these 2 namespaces when they are needed.
SMTP.Dyalog
SendMail.Dyalog

The following is a generic example of how to use SMTP to send an email.
This program can be more efficient but it shows the basic steps:

Code: Select all
 R←SENDEMAIL2;srv;Server;msg;From;To;Subj;Body;Port;SendMail;SMTP;clt
⍝ Used to TEST sending an email via  SMTP
⍝⍝⍝⍝⍝⍝⍝⍝
⍝ bring in SMTP tools (SendMail and SMTP)
 ⎕SE.SALT.Load'C:\Software\MSERVER-SMTP-EMAIL\*.dyalog'
⍝ define the client parameters
 (clt←⎕NS'').(Server Port From Password)←'sub4.mail.dreamhost.com' 465 'alerts@automatonics.com' 'Secret1234'
⍝ define the message parameters
 (msg←⎕NS'').(To Subj Body)←'woodley@brandedoffice.com' 'Hello' 'Hi there!'
⍝ send the mail
 (rc msg client log)←clt SendMail msg
⍝ log off the SMTP server
 {}client.Logoff
⍝ rc is the return code: 0 means there was no error, non-0 means some error was encountered
⍝ msg is a (hopefully) useful message if there was an error
⍝ client is the instance of SMTP client for the server you specified
⍝ log is the vector of responses from the SMTP server; this is useful for debugging


Cheers,

//W
Woodley Butler
Automatonics, Inc.
"Find your head in the APL Cloud"
http://www.APLcloud.com
User avatar
woody
 
Posts: 148
Joined: Tue Dec 28, 2010 12:54 am
Location: Atlanta, Georgia USA

Previous

Return to MiServer

Who is online

Users browsing this forum: No registered users and 1 guest