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) Add File Attachments to an EmailDemonstrates how to add one or more file attachments to an email.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @email int -- Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Email', @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', 'support@chilkatsoft.com' DECLARE @success int EXEC sp_OAMethod @email, 'AddTo', @success OUT, 'Chilkat Admin', 'admin@chilkatsoft.com' -- To add file attachments to an email, call AddFileAttachment -- once for each file to be attached. The method returns -- the content-type of the attachment if successful, otherwise -- returns cknull DECLARE @contentType nvarchar(4000) EXEC sp_OAMethod @email, 'AddFileAttachment', @contentType OUT, 'something.pdf' EXEC sp_OAGetProperty @email, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @email RETURN END EXEC sp_OAMethod @email, 'AddFileAttachment', @contentType OUT, 'something.xml' EXEC sp_OAGetProperty @email, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @email RETURN END EXEC sp_OAMethod @email, 'AddFileAttachment', @contentType OUT, 'something.zip' EXEC sp_OAGetProperty @email, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @email RETURN END EXEC sp_OAMethod @email, 'SaveEml', @success OUT, 'email.eml' IF @success = 0 BEGIN EXEC sp_OAGetProperty @email, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @email RETURN END PRINT 'Saved EML!' EXEC @hr = sp_OADestroy @email END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.