Platforms to show: All Mac Windows Linux Cross-Platform

/CURL/Send Email/older examples/CURLS send email with images


Required plugins for this example: MBS CURL Plugin, MBS Util Plugin, MBS Main Plugin, MBS Images Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/Send Email/older examples/CURLS send email with images

This example is the version from Wed, 3rd Jan 2023.

Project "CURLS send email with images.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() Upload End EventHandler
End Control
Control Result Inherits Label
ControlInstance Result Inherits Label
End Control
Control Server Inherits TextField
ControlInstance Server Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control Username Inherits TextField
ControlInstance Username Inherits TextField
End Control
Control Passwort Inherits TextField
ControlInstance Passwort Inherits TextField
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control ToName Inherits TextField
ControlInstance ToName Inherits TextField
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control FromName Inherits TextField
ControlInstance FromName Inherits TextField
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control Subject Inherits TextField
ControlInstance Subject Inherits TextField
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() DoUpload End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() // update progress label if d<>Nil then if d.ProgressMessage<>"" then result.Text = d.ProgressMessage d.ProgressMessage = "" end if if d.done then TextArea1.text = d.DebugMessages d = nil end if end if End EventHandler
End Control
Control RadioMode Inherits RadioButton
ControlInstance RadioMode(0) Inherits RadioButton
ControlInstance RadioMode(1) Inherits RadioButton
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Function BuildEmailWithAttachment() As string dim em as new EmailMessage em.AddRecipient ToName.text em.FromAddress = FromName.text em.Subject = EncodeEmailSubjectMBS(Subject.text) em.BodyPlainText = "Just a test message." dim pic as Picture = LogoMBS(500) dim jpegData as string = PictureToJPEGStringMBS(pic, 80) dim a as new EmailAttachment a.Data = EncodeBase64(jpegData, 76) a.Name = "test-attachment.jpg" a.MIMEType = "image/jpeg" a.ContentEncoding = "base64" a.MacType = "JPEG" em.Attachments.Append a return em.source End Function
Function BuildEmailWithInline() As string // Xojo EmailAttachment class can't do inlines... // so we build ourselves the email: dim lines() as string lines.Append "From: "+FromName.Text lines.Append "Content-Type: multipart/alternative;" lines.Append " boundary=""test=_6752F02B-F6BD-45B1-816C-F437638AB444""" lines.Append "Subject: "+EncodeEmailSubjectMBS(Subject.Text) lines.Append "Date: Mon, 5 May 2014 20:45:51 +0200" // quick and dirty date... lines.Append "To: "+ToName.Text lines.Append "" lines.Append "" // end of body lines.append "--test=_6752F02B-F6BD-45B1-816C-F437638AB444" lines.append "Content-Transfer-Encoding: 7bit" lines.append "Content-Type: text/plain;" lines.append " charset=us-ascii" lines.append "" // now plain text lines.append "" lines.append "Just a test message." lines.append "" lines.append "" // now multiparts lines.append "" lines.append "--test=_6752F02B-F6BD-45B1-816C-F437638AB444" lines.append "Content-Type: multipart/related;" lines.append " type=""text/html"";" lines.append " boundary=""test=_DA3D6D08-A23E-4D78-8C1D-38F4C6C46D80""" lines.append "" lines.append "" lines.append "--test=_DA3D6D08-A23E-4D78-8C1D-38F4C6C46D80" lines.append "Content-Transfer-Encoding: 7bit" lines.append "Content-Type: text/html;" lines.append " charset=us-ascii" lines.append "" // Now html lines.Append "<html><head><meta http-equiv=""Content-Type"" content=""text/html charset=us-ascii""></head> " lines.Append "<body>" lines.Append "<img src=""cid:C037078C-AD7D-4E93-8DC3-756257691C8B"" align=""right"" width=250 height=250>" lines.Append "Just a test message with inline graphics on right.</body></html>" // now next part lines.append "--test=_DA3D6D08-A23E-4D78-8C1D-38F4C6C46D80" lines.append "Content-Transfer-Encoding: base64" lines.append "Content-Disposition: inline;" lines.append " filename=test-attachment.jpg" lines.append "Content-Type: image/jpeg;" lines.append " x-mac-type=4A504547;" lines.append " name=""test-attachment.jpg""" lines.append "Content-Id: <C037078C-AD7D-4E93-8DC3-756257691C8B>" lines.append "" // now image data dim pic as Picture = LogoMBS(500) dim jpegData as string = PictureToJPEGStringMBS(pic, 80) lines.Append EncodeBase64(jpegData, 76) // end lines.append "" lines.append "--test=_DA3D6D08-A23E-4D78-8C1D-38F4C6C46D80--" lines.append "" lines.append "--test=_6752F02B-F6BD-45B1-816C-F437638AB444--" lines.append "" dim data as string = Join(lines, EndOfLine.Windows) Return ReplaceLineEndings(data, EndOfLine.Windows) End Function
Private Sub DoUpload() Dim e As Integer d=new UploadCURL // this is the file content here: d.InputData = UploadData dim tos(-1) as string tos.Append OptionMailRecipients // disable SSL verification = no security! d.OptionSSLVerifyHost = 0 d.OptionSSLVerifyPeer = 0 d.SetOptionMailRecipients tos d.OptionMailFrom = OptionMailFrom d.OptionUsername = OptionUsername d.OptionPassword = OptionPassword d.OptionURL = OptionURL d.OptionUpload=true d.YieldTime = true d.OptionUsername = "test" d.OptionPassword = "password" Break // change credentials e=d.Perform d.ProgressMessage = "Result: "+str(e) d.done = true End Sub
Sub Upload() // we store stuff in variables here to avoid the ThreadAccessingUIException if RadioMode(0).Value then UploadData = BuildEmailWithAttachment else UploadData = BuildEmailWithInline end if OptionMailFrom = FromName.Text OptionMailRecipients = ToName.Text OptionPassword = Passwort.Text OptionURL = "smtp://"+server.Text OptionUsername = Username.Text Thread1.run End Sub
Note "About"
* Download a specific email id with IMAP: imap://mail.candelatech.com/INBOX/;uid=1 * Download all email for this user with IMAP: imap://mail.candelatech.com/ * Download all email in INBOX for this user with IMAP: imap://mail.candelatech.com/INBOX?ALL * Download all email in INBOX with POP3: pop3://mail.candelatech.com/ * Send email with SSL security using SMTP: smtps://mail.candelatech.com
Property Private OptionMailFrom As string
Property Private OptionMailRecipients As string
Property Private OptionPassword As string
Property Private OptionURL As string
Property Private OptionUsername As string
Property Private UploadData As string
Property d As UploadCURL
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
End Class
Class UploadCURL Inherits CURLSMBS
EventHandler Sub DebugMessage(infotype as integer, data as string, dataSize as Integer) #Pragma unused dataSize #pragma unused infotype t.WriteLine data t.Flush End EventHandler
EventHandler Function Progress(dltotal as Int64, dlnow as Int64, ultotal as Int64, ulnow as Int64, percent as double) As boolean #pragma unused percent #Pragma unused dlnow #Pragma unused dltotal if ultotal=0 then ProgressMessage = "Uploading..." else ProgressMessage = "Uploading "+Format(ulnow/ultotal,"-0%")+" "+stR(ulnow)+" of "+str(ultotal) end if End EventHandler
Sub Constructor() dim f as FolderItem = SpecialFolder.Desktop.Child("test.log") t = TextOutputStream.Create(f) End Sub
Property ProgressMessage As string
Property done As Boolean
Property Private t As TextOutputStream
End Class
End Project

See also:

The items on this page are in the following plugins: MBS CURL Plugin.


The biggest plugin in space...