Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Attach Email as message/rfc822 sub-part to an EmailDemonstrates how to add attach a message/rfc822 email to another email.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- In this example, we'll attach an email loaded from a .eml file to a new email. DECLARE @success int DECLARE @fac int -- Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @fac, 'ReadEntireFile', @emlBytes OUT, 'qa_data/eml/simple.eml' DECLARE @email int -- Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Email', @email OUT EXEC sp_OASetProperty @email, 'Subject', 'This is a test email with an attached email.' EXEC sp_OASetProperty @email, 'Body', 'Test with attached email.' EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Joe', 'joe@example.com' EXEC sp_OASetProperty @email, 'From', 'mary@example.com' EXEC sp_OAMethod @email, 'AttachMessage', @success OUT, @emlBytes EXEC sp_OAMethod @email, 'GetMime', @sTmp0 OUT PRINT @sTmp0 -- ---------------------------------------------------------------------- -- Alternatively, we could do this: DECLARE @emailToBeAttached int -- Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Email', @emailToBeAttached OUT EXEC sp_OAMethod @emailToBeAttached, 'LoadEml', @success OUT, 'qa_data/eml/simple.eml' DECLARE @email2 int -- Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Email', @email2 OUT EXEC sp_OASetProperty @email2, 'Subject', 'This is a test email with an attached email.' EXEC sp_OASetProperty @email2, 'Body', 'Test with attached email.' EXEC sp_OAMethod @email2, 'AddTo', @success OUT, 'Joe', 'joe@example.com' EXEC sp_OASetProperty @email2, 'From', 'mary@example.com' EXEC sp_OAMethod @emailToBeAttached, 'GetMimeBinary', @emlBytes2 OUT EXEC sp_OAMethod @email2, 'AttachMessage', @success OUT, @emlBytes2 PRINT '----' EXEC sp_OAMethod @email2, 'GetMime', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @email EXEC @hr = sp_OADestroy @emailToBeAttached EXEC @hr = sp_OADestroy @email2 END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.