MBS CURL error during run

for mac

I get a run error - “URL using bad/illegal format or missing URL (3)”

below is the code + image of public properties

Please advise …

Dim BusName As string = MainWin.BusName.Text
MBSemail = New CURLEmailMBS

MBSemail.SMTPUsername = UserName.Text
MBSemail.SMTPPassword = Password.Text
MBSemail.SetServer ( Server.text )
MBSemail.UseSSL = True
MBSemail.Constructor ( "UTF-8" )

MBSemail.AddHeader( "X-company: " + BusName)
MBSemail.AddReplyTo (FromEmail.Text, BusName)
MBSemail.SetFrom ( FromEmail.Text, BusName)
MBSemail.Subject = Subject.Text
MBSemail.PlainText = Message.Text

// add to email - maybe more than one
If toEmail.text <> "" then
  MBSemail.AddTo ( ToEmail.Text, MainWin.CusName.Text )
end if
// add CC email
if ToCCEmail.Text <> "" then
  MBSemail.AddCC ( ToCCEmail.Text, MainWin.CusName.Text )
end if

//Set Attachment 
If Attachment <> Nil Then
  MBSemail.AddAttachment(Attachment)
End If

uploadCURL = new CURLSMBS
Dim error as Boolean = uploadCURL.SetupEmail(MBSemail)
Dim ErrorMessage As Integer = uploadCURL.Perform

//Set error text
StatusLabel.Text = uploadCURL.LasterrorText+" ("+ErrorMessage.Totext+")"

Screen Shot 2022-06-20 at 9.01.28 PM

What do you pass for SetServer?

e.g. “mail.yourdomain.com

Your server uses what port and maybe it uses TLS?

MBSemail.UseSSL = False
...
uploadCURL.OptionFTPSSL = 3 // TLS required
uploadCURL.OptionPort = 587

So either you connect with SSL on for first package, which is then port 465. Or you connect with plain text and do a TLS upgrade with port 25 or 587.

Server uses 465 SSL

Here is my code in it’s entirety with certain values specified.
i am setting the CURLSMBS options prior to the .Perform method.
I still get the same error message - "URL using bad/illegal format or missing URL (3)

MBSemail = new CURLemailMBS
MBSemail.SMTPUsername = UserName.Text
MBSemail.SMTPPassword = Password.Text
MBSemail.SetServer ( "smtp.gmail.com" )
MBSemail.UseSSL = False
MBSemail.Constructor ( "UTF-8" )
MBSemail.AddHeader( "X-company: " + BusName)
MBSemail.AddReplyTo (FromEmail.Text, BusName)
MBSemail.SetFrom ( FromEmail.Text, BusName)
MBSemail.Subject = Subject.Text
MBSemail.PlainText = Message.Text

// add to email - maybe more than one
If toEmail.text <> "" then
  MBSemail.AddTo ( ToEmail.Text, MainWin.CusName.Text )
end if
// add CC email
if ToCCEmail.Text <> "" then
  MBSemail.AddCC ( ToCCEmail.Text, MainWin.CusName.Text )
end if

// Send Email

Dim c As New CURLSMBS
Dim er As Integer

c.OptionSSLVersion = 6
c.OptionUseSSL = 3
c.OptionPort = 587

if c.SetupEmail(MBSemail) Then
  er  = c.Perform
  if er = 0 then
    MsgBox "Email Sent"
    InvoiceEmailWin.Close
  End if
End if

// Set error text
StatusLabel.Text = c.LasterrorText + " (" + str(er) + ")"

Please don’t call Constructor directly. Never.
You reset the things you set before.

I got a working example for me:

// send email via gmail

Dim email As New CURLEmailMBS
email.SetFrom "sender@monkeybreadsoftware.com", "John Müller"
email.AddTo "reciever@monkeybreadsoftware.de", "Christian Schmitz"
email.SMTPUsername = "monkeybreadsoftware@gmail.com" // gmail email as account
email.SMTPServer   = "smtp.gmail.com"
email.SMTPPassword = "eotkfwhxnkfayba" // app-specific password, not your gmail login password!

// Content of the Email
email.Subject = "Hello World via gmail"
email.PlainText = "Hello World," + EndOfLine + _
"" + EndOfLine + _
"this Is just a test email With plain Text. 😄" + EndOfLine + _
"" + EndOfLine + _
"Greetings" + EndOfLine + _
"Christian"

// add an attachment
dim pic as Picture = LogoMBS(500)
Dim jpegData As String = Pic.GetData(pic.FormatJPEG)

email.AddAttachment jpegData,  "mbs.jpg", "image/jpeg"

Dim curl As New CURLSMBS

If Not curl.SetupEmail(email) Then
  // problem?
  Dim ee As Integer = curl.Lasterror
  Break 
End If

curl.OptionUseSSL = curl.kUseSSLall
curl.OptionSSLVersion = curl.kSSLVersionTLSv12

Dim error As Integer = curl.Perform

If error = 0 Then
  MessageBox "Mail sent."
Else
  MessageBox "Failed with error "+Str(error)+": "+curl.LasterrorText
  Dim DebugLog As String = curl.DebugData
  Break // read log!
End If

ahh - I never knew that about the constructor.
what is the actual purpose of the constructor ?

and yes i was able to get MBS to work quite well and not sent to spam , that is a big improvement.
and now if it fails i Msgbox the data log and also write the log to a file for future reference. That log is very helpful.

Attachments::
Oh yes, when i do attachments i test to see if the file is .jpg / pdf / gif / jpeg / txt / ect … and set a mime variable accordingly prior to calling the attachment method. i used a FolderItem to read.

the app-specific password i don’t get … how can this be set up ?

Thank you

it is called automatically when you use the “New” keywords.
See Constructor — Xojo documentation

for app passwords: