Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ Delphi FoxPro Java Perl Python Ruby SQL Server VBScript
|
Load MHT and Send as EmailLoad a .MHT file and send it as email.
LOCAL loMailman LOCAL lnSuccess LOCAL loEmail LOCAL loMime LOCAL loMimePart LOCAL n LOCAL i * The mailman object is used for sending and receiving email. loMailman = CreateObject('Chilkat.MailMan2') * Any string argument automatically begins the 30-day trial. lnSuccess = loMailman.UnlockComponent("30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Component unlock failed") QUIT ENDIF * Set the SMTP server. loMailman.SmtpHost = "smtp.comcast.net" * Create a new email object loEmail = CreateObject('Chilkat.Email2') * MHT is MIME and therefore can be loaded directly * into an email object via the email.LoadEml method. * However, if the HTML sub-part of the MIME contains * header fields such as this: * Content-ID: <BalanceSheet> * Content-Disposition: inline; * filename="BalanceSheet" * Content-Type: text/html; * name="BalanceSheet"; * charset="utf-8" * Microsoft Outlook will interpret this as an attached HTML file * rather than the HTML body of the email. Interestingly, * Mozilla Thunderbird handles it correctly, but Outlook does not. * Google's GMail also handles it correctly. Yahoo Mail doesn't * know what to do and displays nothing -- not even the "attachment". * Rather than loading the MHT into the email object, we'll * first load it into a Chilkat MIME object and check for * these headers. We want the header fields of the HTML sub-part * to look like this: * Content-Type: text/html; * charset="utf-8" * To do so, we'll remove the Content-ID and Content-Disposition * header fields, and the "name" attribute from the * Content-Type header. * Note: Chilkat MIME is a separate product. This code * would require licenses to both Chilkat Email and Chilkat Mime, * or alternatively a Chilkat Bundle license (which includes * all Chilkat components). loMime = CreateObject('Chilkat.Mime') lnSuccess = loMime.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Failed to unlock MIME component") QUIT ENDIF lnSuccess = loMime.LoadMimeFile("test.mht") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loMime.LastErrorText) QUIT ENDIF * Is this a multipart/related? If so, find the HTML part, * which should be the 1st sub-part. IF (loMime.IsMultipartRelated() = 1) THEN * Find the HTML part. n = loMime.NumParts FOR i = 0 TO n - 1 loMimePart = loMime.GetPart(i) IF (loMimePart.IsHtml() = 1) THEN EXIT ENDIF RELEASE loMimePart NEXT IF (NOT (loMimePart = NULL )) THEN * Remove these header fields: loMimePart.SetHeaderField("Content-Disposition","") loMimePart.SetHeaderField("Content-ID","") * Remove the "name" attribute from the Content-Type header: loMimePart.Name = "" RELEASE loMimePart ENDIF ENDIF loEmail.SetFromMimeText(loMime.GetMime()) loEmail.Subject = "This is a test" loEmail.From = "Chilkat Support <support@chilkatsoft.com>" loEmail.AddTo("Chilkat Admin","admin@chilkatsoft.com") lnSuccess = loMailman.SendEmail(loEmail) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loMailman.LastErrorText) ELSE =MESSAGEBOX("Mail Sent!") ENDIF |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser