Sending Email Using .NET


It is sometimes useful for an application to be able to send email (for example to get error logs from the field to developers)

       ⎕vr 'SimpleSend'
     ∇ server SimpleSend(from to subject body attach);⎕IO;⎕ML;⎕USING;msg;attdata;mafrom;mato;smtpclient
[1]    ⍝ Simple mail-sending
[2]    ⎕IO ⎕ML ⎕USING←0 3('System.Net.Mail,System.dll')
[3]    mafrom←⎕NEW MailAddress from
[4]    mato←⎕NEW MailAddress to
[5]    msg←⎕NEW MailMessage''
[6]    msg.From←mafrom
[7]    msg.To.Add mato
[8]    msg.Subject←subject
[9]    :If 2=≡body
[10]       body←¯2↓∊body,¨⊂⎕UCS 13 10
[11]   :EndIf
[12]   msg.Body←body
[13]   :If ×⍴attach
[14]       attdata←⎕NEW Attachment(attach'')
[15]       msg.Attachments.Add attdata
[16]   :EndIf
[17]   smtpclient←⎕NEW SmtpClient''
[18]   smtpclient.Host←server
[19]   smtpclient.Send msg
     ∇

Example:

       displayr from
┌2───────────────────────────────────────┐
│ ┌22────────────────────┐ ┌11─────────┐ │
│ │dick@dickbowman.org.uk│ │Dick Bowman│ │
│ └──────────────────────┘ └───────────┘ │
└2───────────────────────────────────────┘
      displayr from to
┌2──────────────────────────────────────────────────────────────────────────────────────┐
│ ┌2───────────────────────────────────────┐ ┌2───────────────────────────────────────┐ │
│ │ ┌22────────────────────┐ ┌11─────────┐ │ │ ┌22────────────────────┐ ┌11─────────┐ │ │
│ │ │dick@dickbowman.org.uk│ │Dick Bowman│ │ │ │dick@dickbowman.org.uk│ │Dick Bowman│ │ │
│ │ └──────────────────────┘ └───────────┘ │ │ └──────────────────────┘ └───────────┘ │ │
│ └2───────────────────────────────────────┘ └2───────────────────────────────────────┘ │
└3──────────────────────────────────────────────────────────────────────────────────────┘
         'xxx.xxx.xx.xx'SimpleSend from to'With attachment'('This is a message' 'with multiple lines' 'and an attachment')'c:\dick\temp\att.txt'


Notes:
Page created 16 March 2009.
Copyright © Dogon Research 2009.