6.10 Sending messages without clients

 < Day Day Up > 



Sometimes a need exists to create and send messages without starting up a client. Now that every Windows server supports SMTP, you can use simple batch command files to connect to port 25 and then build messages through SMTP commands. Another way of approaching the problem is to use a program or script to output a file containing text lines with the necessary SMTP commands to create and send a message. You can then place the text file in the appropriate "pickup" directory for the SMTP virtual server that you want to use on the server and Exchange will send the message for you. Create the message as a simple text file, giving the file a temporary name (the virtual server discards the file as soon as it sends the message) and format the contents according to RFC 822. For example:

Date: 2 Jun 03 1210 GMT To: "Tony Redmond" Tony.Redmond@hpconsulting.com From: "John Smith" John.Smith@acme.com CC: "Jane Jurvis" Jane.Jurvis@acme.com Subject: Notification of System Status     Warning. You should attend to the system because I think all hell is about to break out! 

You can include HTML commands in the file if you want to emphasize information. However, to accomplish this goal, the text becomes more complex, because you have to create a multipart MIME message that respects the rules that allow SMTP to transmit more than just plain text. It is not difficult to create the necessary commands, and after you have done it once it is easy to automate the process in a program or script. Here is the text file used to create the message shown in Figure 6.21.

click to expand
Figure 6.21: Formatted SMTP message.

Date: 2 Jun 03 1210 GMT To: "Tony Redmond" Tony.Redmond@hpconsulting.com From: "System Monitor" System.Manager@hpconsulting.com Subject: Notification of System Status MIME-Version: 1.0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable      <h1>Important Status Report </h1> <br> <h3>There was a problem!</h3> <table border> <tr><td>Log Files</td><td>Check Disk!!!</td></tr> <tr><td>Backup Job</td><td>Status cannot be verified</ td></tr> </table> <p> Warning. You should attend to the system because I think all hell is about to break out! 

It is easy to make a mistake when you generate commands to create MIME-formatted messages, so it is wise to verify that everything works by putting a message into the pickup directory and seeing whether it arrives. If Exchange delivers the message to the right Inbox, you know that the commands are right. On the other hand, if the message ends up in the virtual server's "badmail" directory, you know that an error is present. Usually, there is something wrong in the basic SMTP directives in the message header (To:, Cc:, and so on), but a malformed MIME bodypart can also cause problems.

If you do not want to mess around with programs, scripts, or SMTP commands, you can use the MAPISEND utility, which is part of the Exchange Resource Kit, to create and send messages. MAPISEND works by connecting to a mailbox to send a message. For example, the command:

MAPISEND –u "Exchange" –r John.Doe@xyz.com -s "The moon is full" –m "The moon is full tonight. Look outside your window" -v

performs the following actions:

  • Log on to the mailbox identified in the profile called "Exchange." Just like all other MAPI clients, a profile must exist on the client before MAPISEND can make a connection. If security credentials are already present (in other words, an account has already been logged in to), they are used for authentication. Alternatively, you can pass the password with the –p parameter.

  • The message is addressed to the recipient John.Doe@xyz.com. You can pass any address that Exchange can resolve, including the name or email address of a distribution group.

  • The message subject is set to be "The moon is full."

  • The text of the message is set to be "The moon is full tonight. Look outside your window."

  • The –v command switch tells MAPISEND that it must verify that it successfully sent the message.

As with all simple utilities, there is not much more to say. You cannot format the message text by adding colors, emphasis, or different fonts, but it is more than enough to send a short note. Typical uses include informing administrators that important system housekeeping jobs are finished, or sending a message to a pager or via SMS to a GSM phone to let the recipient know that a problem has occurred.

If you prefer not to use MAPISEND, the BLAT[9] utility or a commercial product such as Postie (available from www.infradig.com) offers another alternative. For example, here is the command line to use BLAT to send a text file called "mail.txt" to the recipient Jane.Doe@hp.com from a user called John.Doe@hp.com. The message subject is set to be "Urgent Message." Messages to notify system administrators that a problem has occurred with a program or other task are often sent in this manner, and since you can use any valid SMTP address, the messages can be sent to pagers, cell phones, and other devices.

BLAT mail.txt –t jane.doe@hp.com –f john.doe@hp.com – subject "Urgent Message"

New utilities appear all the time, so browsing the various support forums dedicated to Windows and Exchange may turn up another program that is closer to your needs.

[9] . See http://www.interlog.com/~tcharron/blat.html.



 < Day Day Up > 



Microsoft Exchange Server 2003
Microsoft Exchange Server 2003 Administrators Pocket Consultant
ISBN: 0735619786
EAN: 2147483647
Year: 2003
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net