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
(PowerBuilder) Forward by Attaching the Existing Email to a New EmailDemonstrates how to forward an email by attaching the email to a new email. This example uses the AttachEmail method, which is new in Chilkat v9.5.0.87. This example reads an email from an IMAP server, attaches the email to a new email, and sends the new email.
integer li_rc oleobject loo_Imap integer li_Success integer li_NumEmails oleobject loo_Email oleobject loo_EForward oleobject loo_Mailman // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Read the 1st (most recent) email in an Inbox. loo_Imap = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap") if li_rc < 0 then destroy loo_Imap MessageBox("Error","Connecting to COM object failed") return end if // Connect to an IMAP server. loo_Imap.Ssl = 1 loo_Imap.Port = 993 li_Success = loo_Imap.Connect("imap.someMailServer.com") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Login li_Success = loo_Imap.Login("myLogin","myPassword") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Select an IMAP mailbox li_Success = loo_Imap.SelectMailbox("Inbox") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if li_NumEmails = loo_Imap.NumMessages // Fetch the email at the last sequence number. // (We are assuming the Inbox has at least 1 email) loo_Email = loo_Imap.FetchSingle(li_NumEmails,0) if loo_Imap.LastMethodSuccess = 0 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Disconnect from the IMAP server. loo_Imap.Disconnect() Write-Debug loo_Email.Subject // Create a new email. The email we just read will be attached to this email. loo_EForward = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_EForward.ConnectToNewObject("Chilkat.Email") loo_EForward.AddTo("Chilkat Support","support@chilkatsoft.com") loo_EForward.FromAddress = "matt@someMailServer.com" loo_EForward.FromName = "Matt" loo_EForward.Subject = "This is an email with another email attached." loo_EForward.SetHtmlBody("<p>Hello, this is an email I'm forwarding to you. See the attached email.</p>") // Attach the email. loo_EForward.AttachEmail(loo_Email) // We could save the .eml, then double-click on it to view in our mail program, such as Outlook or Thunderbird.. loo_EForward.SaveEml("qa_output/forward.eml") // We could send (forward) the email.. loo_Mailman = create oleobject // Use "Chilkat_9_5_0.MailMan" for versions of Chilkat < 10.0.0 li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan") loo_Mailman.SmtpHost = "smtp.someMailServer.com" loo_Mailman.SmtpUsername = "myLogin" loo_Mailman.SmtpPassword = "myPassword" loo_Mailman.SmtpPort = 587 loo_Mailman.StartTLS = 1 li_Success = loo_Mailman.SendEmail(loo_EForward) if li_Success <> 1 then Write-Debug loo_Mailman.LastErrorText destroy loo_Imap destroy loo_EForward destroy loo_Mailman return end if li_Success = loo_Mailman.CloseSmtpConnection() if li_Success <> 1 then Write-Debug "Connection to SMTP server not closed cleanly." end if Write-Debug "Mail Sent!" destroy loo_Email destroy loo_Imap destroy loo_EForward destroy loo_Mailman |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.