Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Debug / Verify SMTP SessionAn SMTP client, such as the Chilkat Email component or Outlook, is responsible for passing an email to an SMTP server. Typically, the client connects to a single (i.e. your) SMTP server that acts as a relay to deliver email destined for a remote mail server. The "handoff" to your SMTP server is the 1st step in the mail delivery process. An SMTP client can only ensure that this handoff happens without error. After the handoff is complete, it is the SMTP server's job to relay the email to a remote SMTP server (or perhaps some intermediate server) to complete delivery. If the recipient indicates that he/she never received the email, the 1st step in debugging is to verify that the "handoff" happened without error. This is what this example is intended to demonstrate. If there are no errors in the "handoff", then the non-delivery problem occurred downstream (i.e. at some point after your SMTP server accepted the email from you, the SMTP client). The most common cause for "non-delivery" is that the recipient's anti-SPAM filters rejected the email, or automatically placed it in his/her Junk email folder. Ask the recipient to check for that possibility. If the recipient claims that anti-SPAM is not the cause, then you'll need to check your SMTP server's logs, and the recipient should check his/her mail server logs. Try to verify if your SMTP server successfully relayed the email. For the remote (receiving) mail server, try to see if the logs indicate that the mail was received. If so, was it rejected?
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) -- The interesting part of this example is near the bottom of this -- page where the SmtpSessionLog is captured and displayed. -- -- The mailman object is used for sending and receiving email. DECLARE @mailman int EXEC @hr = sp_OACreate 'Chilkat.MailMan2', @mailman OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Any string argument automatically begins the 30-day trial. DECLARE @success int EXEC sp_OAMethod @mailman, 'UnlockComponent', @success OUT, '30-day trial' IF @success <> 1 BEGIN PRINT 'Component unlock failed' RETURN END -- Set the SMTP server. EXEC sp_OASetProperty @mailman, 'SmtpHost', 'smtp.chilkatsoft.com' -- Set the SMTP login/password (if required) EXEC sp_OASetProperty @mailman, 'SmtpUsername', 'myLogin' EXEC sp_OASetProperty @mailman, 'SmtpPassword', 'myPassword' -- Create a new email object DECLARE @email int EXEC @hr = sp_OACreate 'Chilkat.Email2', @email OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @email, 'Subject', 'This is a test' EXEC sp_OASetProperty @email, 'Body', 'This is a test' EXEC sp_OASetProperty @email, 'From', 'Chilkat Support <support@chilkatsoft.com>' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Chilkat Gmail', 'chilkat.support@gmail.com' EXEC sp_OAMethod @email, 'AddTo', NULL, 'Chilkat Yahoo', 'chilkat_software@yahoo.com' -- Call SendEmail to connect to the SMTP server and send. -- The connection (i.e. session) to the SMTP server remains -- open so that subsequent SendEmail calls may use the -- same connection. EXEC sp_OAMethod @mailman, 'SendEmail', @success OUT, @email IF @success <> 1 BEGIN EXEC sp_OAGetProperty @mailman, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END -- Some SMTP servers do not actually send the email until -- the connection is closed. In these cases, it is necessary to -- call CloseSmtpConnection for the mail to be sent. -- Most SMTP servers send the email immediately, and it is -- not required to close the connection. We'll close it here -- for the example: EXEC sp_OAMethod @mailman, 'CloseSmtpConnection', @success OUT IF @success <> 1 BEGIN PRINT 'Connection to SMTP server not closed cleanly.' END EXEC sp_OAGetProperty @mailman, 'SmtpSessionLog', @sTmp0 OUT PRINT @sTmp0 -- A sample SMTP session log is included below. -- There are two key items to verify: -- 1) Each recipient in the email (To, CC, BCC) should be present in the log -- in a "RCPT TO" command. You may visually verify that the response -- from the SMTP server was "250 OK" for each recipient. -- (Chilkat also provides a way to get the failed RCPT TO responses programmatically...) -- 2) The "DATA" command is followed by the client sending the full MIME source of the email, -- followed by a single line containing a ".". -- The final response from the SMTP server should be a "250 OK". -- If all of the RCPT TO commands were successful, and the final SMTP response was success, -- then the client-to-SMTP-server handoff was successful. If a delivery problem is reported by -- a recipient, the problem occurred downstream of this "handoff". -- 220 mail.chilkatsoft.com ESMTP 648143d3667b3045487bb901cdbbf649 -- 250-mail.chilkatsoft.com -- 250-PIPELINING -- 250-SIZE 100000000 -- 250-DATAZ -- 250-AUTH LOGIN PLAIN -- 250 8BITMIME -- AUTH LOGIN -- 334 xxxxxxxxxxxx -- 334 xxxxxxxxxxxx -- 235 nice to meet you -- MAIL FROM:<support@chilkatsoft.com> -- 250 ok -- RCPT TO:<chilkat.support@gmail.com> -- 250 ok -- RCPT TO:<chilkat_software@yahoo.com> -- 250 ok -- DATA -- 354 go ahead -- MIME-Version: 1.0 -- Date: Wed, 19 Mar 2008 08:40:52 -0500 -- X-Mailer: Chilkat Software Inc (http://www.chilkatsoft.com) -- X-Priority: 3 (Normal) -- Subject: This is a test -- Content-Type: text/plain -- Content-Transfer-Encoding: quoted-printable -- From: "Chilkat Support" <support@chilkatsoft.com> -- To: "Chilkat Gmail" <chilkat.support@gmail.com>, -- "Chilkat Yahoo" <chilkat_software@yahoo.com> -- Message-ID: <CHILKAT-MID-02039824-9296-78bb-fff7-88fe94e86148@CK2007> -- -- This is a test -- . -- 250 ok 1205934062 qp 28546 by mail.chilkatsoft.com END GO |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.