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 an Email using CreateForwardReads an email from an IMAP server, creates a forward version of the email using the CreateForward method, and sends the email to another recipient.
integer li_rc oleobject loo_Imap integer li_Success integer li_NumEmails oleobject loo_Email oleobject loo_EForward oleobject loo_SbHtmlBody oleobject loo_SbPtBody 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 loo_EForward = loo_Email.CreateForward() // The eForward email has no To or CC recipients yet. // Add one or more.. loo_EForward.AddTo("Chilkat Support","support@chilkatsoft.com") // We also need to specify the From name/address. loo_EForward.FromAddress = "matt@someMailServer.com" loo_EForward.FromName = "Matt" // If we wish to add text at the start of the email body: loo_SbHtmlBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbHtmlBody.ConnectToNewObject("Chilkat.StringBuilder") if loo_EForward.HasHtmlBody() = 1 then loo_SbHtmlBody.Append(loo_EForward.GetHtmlBody()) loo_SbHtmlBody.Prepend("<p>Hello, this is an email I'm forwarding to you...</p>") loo_EForward.SetHtmlBody(loo_SbHtmlBody.GetAsString()) end if loo_SbPtBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbPtBody.ConnectToNewObject("Chilkat.StringBuilder") if loo_EForward.HasPlainTextBody() = 1 then loo_SbPtBody.Append(loo_EForward.GetPlainTextBody()) loo_SbPtBody.Prepend("Hello, this is an email I'm forwarding to you...~r~n~r~n") loo_EForward.SetTextBody(loo_SbPtBody.GetAsString(),"text/plain") end if // 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_SbHtmlBody destroy loo_SbPtBody 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_EForward destroy loo_Email destroy loo_Imap destroy loo_SbHtmlBody destroy loo_SbPtBody destroy loo_Mailman |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.