eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SMTPClient':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SMTPClient


Inheritance:

   Object
   |
   +--NVTClient
      |
      +--SMTPClient

Package:
stx:goodies/communication
Category:
Net-Communication-SMTP
Version:
rev: 1.34 date: 2022/03/11 19:34:53
user: cg
file: SMTPClient.st directory: goodies/communication
module: stx stc-classLibrary: communication

Description:


a very simple SMTP mail client.
Right now, there are two entries:
    sendMessageString:
        which expects a string argument, containing all of
        the mail info (from lines, subject etc.)
    
    sendMessage:
        which expects a letter object, which itself is able
        to convert itself to a string. At the time of writing,
        such a letter object does not exist,

copyright

COPYRIGHT (c) 2002 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

class initialization
o  initialize
self initialize.

signal constants
o  smtpErrorSignal


Instance protocol:

accessing
o  addHeaderLine: aString
add a string (in the form 'keyword: line') to be sent in the mail header

o  addHeaderLines: aCollection
add a string (in the form 'keyword: line') to be sent in the mail header

o  clientHostName

o  clientHostName: something

defaults
o  defaultPassword

o  defaultPort
SMTPS

o  defaultUser

initialization
o  initialize

operations
o  sendMessage: rfc822Message
send an rfc822Message (Net::MailMessage)

o  sendMessage: rfc822Message to: receiver
send an rfc822Message

o  sendMessage: rfc822Message toAll: receivers
send an rfc822Message

o  sendMessageString: rfc822MessageString to: receiver
send an rfc822MessageString

o  sendMessageString: rfc822MessageString toAll: receivers
send an rfc822MessageString

Usage example(s):

     |snmp|

     snmp := SMTPClient new.
     snmp connectTo:'exept'.
     snmp userName:'cg@exept.de'.
     snmp sendMessageString:'this is a test message\.\last line' withCRs to:'cg@exept.de'.
     snmp close

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypString to: receiver
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypString to: receiver cc: ccReceiver bcc: bccReceiver
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypString to: receiver fromLabel: fromLabel
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypeString toAll: receivers
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypeString toAll: receivers fromLabel: fromLabel
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypeString toAll: receivers toAllCc: ccReceivers toAllBcc: bccReceivers

o  sendMessageString: rfc822MessageString withSubject: aSubjectString contentType: aContentTypeString toAll: receivers toAllCc: ccReceivers toAllBcc: bccReceivers fromLabel: fromLabel
send an rfc822MessageString

Usage example(s):

    |smtp|

     smtp := SMTPClient new.
     smtp connectTo:'bar'.
     smtp userName:'foo@bar.baz'.
     smtp sendMessageString:('this is a test message cc/bcc \.\last line' withCRs) 
          withSubject:'test cc/bcc [4]' 
          contentType:nil 
          toAll:#('foo@bar.baz') 
          toAllCc:#('fooCC@bar.baz') 
          toAllBcc:#('fooBcc@bar.baz').
     smtp close

o  sendMessageString: rfc822MessageString withSubject: aSubjectString to: receiver
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString to: receiver cc: ccReceiver bcc: bccReceiver
send an rfc822MessageString

o  sendMessageString: rfc822MessageString withSubject: aSubjectString toAll: receivers
|snmp|

snmp := SMTPClient new.
snmp connectTo:'exept'.
snmp userName:'penk@exept.de'.
snmp sendMessageString:('this is a test message\.\last line' withCRs) withSubject:'Message from SmalltalkX' to:'penk@exept.de'.
snmp close

o  verifyUser: userName
|snmp|

snmp := SMTPClient new.
snmp connectTo:'exept'.
Transcript showCR:(snmp verifyUser:'fooUser').
snmp close

private - commands & responses
o  handleReplyCode: replyCode
Raise an error if the last response from the SMTP server has an error.

o  sendGoodByeCommand
(comment from inherited method)
invoked before the socket connection is shutDown.
A subclass implementation may want to redefine this for a graceful goodBy
(typically sending a quit-command)

private - connection setup
o  getInitialConnectResponse
(comment from inherited method)
invoked right after the socket connection has been setup;
subclass implementation should read all initial hello-bla

o  performLoginSequence
invoked after the socket connection has been setup

o  sendEhlo
send the extended EHLO command and get the supported capabilities


Examples:


Use host:port - port is optional.
    SMTPClient new
        useSTARTTLS;
        connectTo:'exeptn.bh.exept.de:587' user:'stefan';
        sendMessageString:'This is a test message\.\last line' withCRs 
            withSubject:'STARTTLS testmail' 
            to:'stefan@exept.de';
        close.
    SMTPClient new
        userName:'sr';
        connectTo:(IPSocketAddress localHost);
        sendMessageString:'this is a test message\.\last line' withCRs 
                to:'stefan.reise@gmx.de';
        close.
    SMTPClient new 
        useSSL;
        userName:'stefan';
        connectTo:(IPSocketAddress hostName:'exeptn');
        sendMessageString:'This is a test message \.\last line' withCRs 
            withSubject:'SSL testmail' 
            to:'stefan@exept.de';
        close.
    |m|

    m := Net::MailMessage new.
    m 
        from:'stefan.reise@exept.de';
        to:'stefan.reise@gmx.de';
        subject:'Test von stx';
        contents:'Dies ist ein mailtext';
        yourself.

    SMTPClient new
        userName:'stefan.reise';
        password:'rappel72';
        connectTo:(IPSocketAddress hostName:'mail.exept.de');
        sendMessage:m;
        close.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 17:10:01 GMT