Entry
Language: Computer: BBCBASIC: Windows: How to possibly send an e-mail via BBCBASIC for Windows?
Oct 22nd, 2006 13:59
Knud van Eeden, Richard Russell
----------------------------------------------------------------------
--- Knud van Eeden --- 31 January 2021 - 01:14 am --------------------
Language: Computer: BBCBASIC: Windows: How to possibly send an e-mail
via BBCBASIC for Windows?
---
Method:
Use the socklib library to connect to your SMTP mail server
at port 25, then send the e-mail in the correct format to it
---
Here a simple BBCBASIC program to send e-mails
(this has been tested with the Argosoft e-mail server,
with which it works fine (you can e.g. omit the 'HELO'
command in that case. In general you will have to include
this 'HELO' command with e.g. other SMTP servers in
your domain (e.g. the SMTP server of your provider).
In that case use e.g. the sendmail.bbc program.
--- cut here: begin --------------------------------------------------
REM. BBCBASIC for Windows program to send an email using SMTP
:
INSTALL @lib$ + "SOCKLIB"
:
PROCsendmailSimple( "127.0.0.1", \ your SMTP server
\ "test1@mylocalpc1.com", \ From
\ "test2@mylocalpc1.com", \ To
\ "Test of PROCsendmail", \ Subject
\ "This is a test message." )
:
END
:
:
:
DEF PROCsendmailSimple( smtp$, from$, to$, subject$, body$ )
LOCAL skt%
DEBUG% += 1
PROC_initsockets
skt% = FN_tcpconnect( smtp$, "mail" )
IF skt% <= 0 skt% = FN_tcpconnect( smtp$, "25" )
IF skt% <= 0 ERROR 100, "Failed to connect to mail server"
PROCsend( skt%, "MAIL FROM: " + from$ )
PROCsend( skt%, "RCPT TO: " + to$ )
PROCsend( skt%, "DATA" )
PROCsend( skt%, "FROM: " + from$ )
PROCsend( skt%, "TO: " + to$ )
PROCsend( skt%, "SUBJECT: " + subject$ )
PROCsend( skt%, "" )
PROCsend( skt%, body$ )
PROCsend( skt%, "." )
PROCsend( skt%, "QUIT" )
ENDPROC
:
DEF PROCsend(skt%,cmd$)
LOCAL reply$
IF DEBUG% PRINT "T: "+cmd$
IF FN_writelinesocket(skt%,cmd$) < 0 THEN
ERROR 100, "Send failed"
ENDIF
IF FN_readlinesocket(skt%, 200, reply$) > 0 THEN
IF DEBUG% PRINT "R: "+reply$
ENDIF
WHILE FN_readlinesocket(skt%, 10, reply$) > 0
IF DEBUG% PRINT "R: "+reply$
ENDWHILE
ENDPROC
:
--- cut here: end ----------------------------------------------------
A typical conversation is
--- cut here: begin --------------------------------------------------
T: MAIL FROM: test1@mylocalpc1.com
R: 220 ArGoSoft Mail Server Freeware, Version 1.8 (1.8.8.8)
T: RCPT TO: test2@mylocalpc1.com
T: DATA
R: 250 Sender "test1@mylocalpc1.com" OK...
T: FROM: test1@mylocalpc1.com
T: TO: test2@mylocalpc1.com
R: 250 Recipient "test2@mylocalpc1.com" OK...
T: SUBJECT: Test of PROCsendmail
R: 354 Enter mail, end with "." on a line by itself
T:
T: This is a test message.
T: .
R: 250 Message accepted for delivery.
<w8ykf525xoejmc8.221020060504@12345678>
T: QUIT
R: 221 Aba he
--- cut here: end ----------------------------------------------------
If you should use from the MSDOS command line
telnet <your STMP server IP address or computer name> 25
to send the same commands, you will see a similar conversation
--- cut here: begin --------------------------------------------------
220 ArGoSoft Mail Server Freeware, Version 1.8 (1.8.8.8)
MAIL FROM: test1@mylocalpc1.com
250 Sender "test1@mylocalpc1.com" OK...
RCPT TO: test2@mylocalpc1.com
250 Recipient "test2@mylocalpc1.com" OK...
DATA
354 Enter mail, end with "." on a line by itself
FROM: test1@mylocalpc1.com
TO: test2@mylocalpc1.com
SUBJECT: Test of PROCsendmail
This is a test message.
.
250 Message accepted for delivery.
<w8ykf525xoejmc8.221020060504@12345678>
QUIT
--- cut here: end ----------------------------------------------------
===
Sending e-mails from your locally installed SMTP server to another e-
mail account
Usually this will not work in case the receiving SMTP server(s) require
authentication (e.g. Google does).
In that case you should use the SMTP server of your own provider
as the SMTP server.
===
Sending e-mails from your own computer to other computers
using the SMTP server of your provider
If you want to send e-mail to any e-mail address (e.g. to GMail),
you will
1. Have to use the SMTP server information of your own provider
(in general you will have to use an SMTP server which is
located in your own domain).
This because this SMTP server does not require authentication
from computers in its own domain, of which your computer is one.
2. Use e.g. your e-mail address at your own provider in the 'From'
3. Use any other e-mail address in the 'To'
4. This is tested successfully with the original sendmail.bbc program
http://groups.yahoo.com/group/bb4w/files/Miscellane
ous/sendmail.bbc
5. In general thus you use:
PROCsendmail("SMTP server IP address or computer name of your
own ISP provider", \ SMTP server
\ "myusername1@myprovider.com", \ From
\ "myusername2@someotherprovider.com", \ To
\ "", \ Cc
\ "", \ Bcc
\ "Test of PROCsendmail", \ Subject
\ "", \ Reply-to
\ "This is a test message")
END
6. E.g. to send e-mails to Google GMail, you could e.g. use:
(successfully tested using sendmail.bbc)
PROCsendmail("smtp.myprovider.com", \ SMTP server
\ "john@myprovider.com", \ From
\ "someusername@gmail.com", \ To
\ "", \ Cc
\ "", \ Bcc
\ "Test of PROCsendmail", \ Subject
\ "", \ Reply-to
\ "This is a test message")
END
===
To test sending your e-mail using a SMTP server
(e.g. installed on your local computer)
Use e.g. the default SMTP server which comes with IIS
(installed by default on Microsoft Windows XP Professional),
or use Microsoft Exchange, or
download and install e.g. the free e-mail server 'Argosoft',
http://www.argosoft.com/RootPages/Download.aspx
then select agsmail.exe, to start the mailserver, run 'mailserver.exe'
after installation,
create a new accounts (username=test1, password=test, and another
username=test2, test3, ...),
Create a domain name (e.g. goto 'Options', choose tab 'Local domains'
and fill in e.g. 'mylocalpc1.com').
You can then send e-mails to e.g. test1@mylocalpc1.com, and the e-mail
server
should receive it (check the 'view' of the e-mail server icon in the
taskbar
to check if it was transferred OK)
and send an e-mail to it.
---
Troubleshooting Argosoft e-mail server
If you get message '551 User not local. We don't relay',
add a string (e.g. mylocalpc1.com (this should be a
non existing domain name (e.g. google.com is an existing
domain and that will not work, and it can also not be left blank,
and your computer must be in the same domain if it exists)
to this mail server options ('Options'->'Local domains',
type your self chosen domain name (e.g. mylocalpc1.com,
this is going from then on be the part after the '@' in your
e-mail, e.g. test1@mylocalpc1.com), then click button 'Add',
button 'OK'.
---
If you get message that 'port is in use', stop e.g. IIS smtp server
(shown as the process 'inetinfo') via IIS administrative tools.
---
You can use http://www.sysinternals.com program 'tcpview'
or
the MSDOS command
netstat -a
to check which processes are running on which ports (e.g. port 110 for
POP and port 25 for SMTP), it should show 'mailserver'.
===
You can also kill processes using the command
tasklist
to see the name of the process,
(e.g. inetinfo)
and
taskkill /F /IM <that process name>.exe
e.g.
taskkill /F /IM inetinfo.exe
to remove it.
---
To check what is going on on port 25, use e.g. a port analyzer
like the free Ethereal program
http://www.ethereal.com/download.html
and look for the SMTP protocol (you can e.g. apply a filter
port = 25
or a filter
( smtp.res || smtp.rqs )
---
To get the IP address of the computer on which you installed the mail
server,
type 'ipconfig' or get the computer name using
MSDOS command 'set computername'.
If you install it on your local pc you can use by default as IP address
127.0.0.1
---
If you get 'failed to connect to email server', then start
your mail server e.g. via the icon taskbar (right click,
choose 'start'),
or if it is not running at all, run the program 'mailserver.exe'
in the Argosoft directory on your harddisk.
---
To send e-mails, see and use e.g. the program 'sendmail.bbc'
which is present in your BBCBASIC for Windows v5.30a directory,
and call it with your information
(to debug, set e.g. DEBUG% += 1 in sendmail.bbc.
If you do not see 'Message accepted for delivery' in debug mode,
then you can be pretty sure that your e-mail has not been sent
away and something has gone wrong)
===
===
Method:
Directly call the Microsoft Windows ShellExecute() API with the mailto
command
1. -Create the following program
(put the wrapped line on 1 single line, and everything between the
double quotes at "mailto..." without spaces together)
--- cut here: begin --------------------------------------------------
recipient$ = "TheReceiver@ddd.ddd"
subject$ = "Sending emails from BBCBasic for Windows"
body$ = "This is a test"
command$ = "mailto:"+recipient$+"?subject="+subject$+"&body="+body$
SYS "ShellExecute", @hwnd%, 0, command$, 0, "", 0
END
--- cut here: end ----------------------------------------------------
2. -If you run this program, it will start
Microsoft Outlook Express
(or in general your default e-mail client)
with the following possible parameters
(content free to choose by you)
1. -Your to e-mail address
2. -Your from e-mail address
3. -Your .cc e-mail address
4. -Your e-mail subject text
5. -Your e-mail body text
===
Method:
You could use OSCLI to start Microsoft Internet Explorer with
the 'mailto' parameter.
e.g.
Steps: Overview:
1. -Create the following program
(put the wrapped line on 1 single line, and everything between the
double quotes at "mailto..." without spaces together)
--- cut here: begin --------------------------------------------------
OSCLI( "c:\progra~1\intern~1\iexplore.exe" + " "
+ "mailto:to@ddd.ddd?
from=from@ddd.ddd&cc=cc@ddd.ddd&subject=yoursubjecttext&body=yourbodyte
xt" )
END
--- cut here: end ----------------------------------------------------
1. -You might have to adapt the path to
the iexplore.exe program to the
path on your computer
2. -If you run this program, it will start
Microsoft Outlook Express
(or in general your default e-mail client)
with the following parameters
(content free to choose by you)
1. -Your to e-mail address
2. -Your from e-mail address
3. -Your .cc e-mail address
4. -Your e-mail subject text
5. -Your e-mail body text
===
Tested successfully on
Microsoft Windows XP Professional (service pack 2),
running BBCBASIC for Windows v5.30a
===
Internet: see also:
---
Language: Computer: BBCBASIC: Windows: E-mail: Link: Overview: Can you
give an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/39340/fid/768
----------------------------------------------------------------------