************************************* * * * DB/C Newsletter * * November 1999 * * * ************************************* News and Comments Thanks to the several people who commented on last month's Java speech in this space. Generally, the responses were positive. The feud between the US government and Microsoft moves to Chicago for the next few weeks. Judge Posner, Chief Judge of the Chicago-based 7th Circuit, has been appointed mediator between the government and Microsoft. His political views are quite interesting - he's not known for going along with the crowd. It will be interesting to see if he can get the two sides to agree to a settlement. This month we provide a complete, working DB/C program that transmits Internet email. I'd bet several readers of this newsletter can put this code to immediate use. don.wills@swc.com ***************************************************************************** Sending Email From a DB/C Program With the addition of support for TCP/IP in DB/C 9.1, DB/C became an Internet-capable programming language. Previous newsletters have provided sample code for dealing with FTP and HTTP, two important TCP-based protocols. The purpose of those articles and sample code wasn't to provide useful tools, but rather was to provide insight into how to use TCP/IP in a DB/C program. With this article, we provide sample code that implements sending an email (no attachments) using the Simple Mail Transfer Protocol (SMTP). Unlike the previous samples, this code is immediately useful to allow you to send email messages to anyone on the Internet. True to its name, the SMTP protocol is generally simple to use. If you know a few commands, you can actually just sit down at a telnet session and type in the SMTP commands to send, check and receive email manually, without the use of any email client program. The essential element to make this work is to have access to an SMTP server to handle the actual transmission of the message to its intended recipient. All you need to know is the DNS name of that server. For example, the name of the Subject, Wills and Company SMTP server is mailhost.swc.com. The program itself is below. Aside from the few SMTP commands that are used, the only odd aspect is how the message body is terminated. It is terminated whenever the sequence CR, LF, ".", CR, LF is encountered. Along with the QUIT SMTP command, that's what the 3 lines before the comclose do. The special ending sequence is also the reason for the if statement within the for loop. This sequence eliminates the possibility of a premature end of the message. Long-time readers of this newsletter may recall that several years ago a DB/C Newsletter was sent out that was abruptly shortened. The remaining text of that newsletter was omitted. The cause of that error was that the email client software wasn't handling the case where a message line consisted only of a period. This program was tested using DB/C DX under Windows 2000 talking to a Windows NT Exchange Server. It should also work fine with any other version of DB/C DX along with any SMTP server. Here is the program: ............................................................................. . . this is an example of how to call the sendmail routine . msgtext char 80[10] display *es, "test send mail program" move "This is a sample message." to msgtext[1] move "Regards, " to msgtext[2] move "Don" to msgtext[3] call sendmail with "mailhost.swc.com", "dbc@swc.com": "don.wills@swc.com", "Sample", msgtext display "done" stop ............................................................................. . . send mail routine . mail is sent using the SMTP mail server specified by the mailhost operand . from and to are fully specified Internet email addresses . subject is the subject of the email . msg is an array of character variables that contains the message . sendmail routine mailhost, from, to, subject, msg mailhost char @ from char @ to char @ subject char @ msg char @[] cfile comfile i1 int 5 n1 int 5 date char 31 comopen cfile, ("TCPCLIENT " + mailhost + " 25") call send1 with "HELO" call send1 with "" call send1 with ("MAIL FROM: <" + from + ">") call send1 with ("RCPT TO: <" + to + ">") call send1 with "DATA" call setdate call send2 with ("Date: " + date) call send2 with ("To: " + to) call send2 with ("From: " + from) call send2 with ("Subject: " + subject) call send2 with "" type msg to i1, n1 for i1 from 1 to n1 if (msg[i1] = ".") call send2 with ". " else if (msg[i1] != "") call send2 with msg[i1] endif repeat call send2 with "" call send1 with "." call send1 with "QUIT" comclose cfile return timeout form "30" crlf init 0x0D, 0x0A sendresp char 100 sendtext char @ . . send with wait for response . send1 lroutine sendtext comclr cfile send cfile, timeout; *ll, sendtext, crlf comwait sendclr cfile recv cfile, timeout; sendresp comwait comtst cfile return endroutine . . send with no wait for response . send2 lroutine sendtext comclr cfile send cfile, timeout; *ll, sendtext, crlf comwait return endroutine . . set the date variable to "day, dd mmm yyyy hh:mm:ss -nnnn" . where -nnnn is GMT offset (-0600 is US Central Standard Time). . setdate work char 24 clock calendar to work move work to date reset date to 3 append ", " to date reset work to 9 append work to date reset date to 7 append " " to date reset work to 5 append work to date reset date to 11 append " " to date reset work to 12 append work to date append " -0600" to date reset date return endroutine ............................................................................. ***************************************************************************** DB/C Class Schedule Class: DB/C DX and JX Language Fundamentals Date: January, 2000 (tentative) Location: Oak Brook, Illinois For information, contact Judi Tamkevic at: voice 630.572.0240 email dbc@swc.com ***************************************************************************** Subscribing to the DB/C Newsletter If you don't already have the DB/C Newsletter delivered to your email address and would like to have it emailed to you when it is produced, just send an email message to 'request@swc.com' and put the line 'subscribe dbcnews' in the body of the email message (omit the ' characters). The newsletter will be delivered to the email address from which the message was sent. To stop delivery, put the line 'unsubscribe dbcnews' in the body of the message.