Private Sub SendMail
Dim mProdukt As String
Dim mMenge As String
Dim memailtext As String
If Main.mMarktProdukte = "" Then
Dim sf As Object = xui.Msgbox2Async("Wählen Sie erst einen Markt aus.", "", "", "Zurück", "", Null)
Wait For (sf) Msgbox_Result (Result As Int)
If Result = xui.DialogResponse_Cancel Then
Return
End If
End If
'initialize the database
#If B4J
SQL1.InitializeSQLite(xui.DefaultFolder, "einkauf.db3", True)
#Else
SQL1.Initialize(xui.DefaultFolder, "einkauf.db3", True)
#End If
Dim rs As ResultSet = SQL1.ExecQuery("SELECT * FROM einkauf WHERE ok = " & 1 & " AND markt = '" & Main.mMarktProdukte & "' ORDER BY lfdnr ASC")
Do While rs.NextRow
mProdukt = rs.GetString("produkt")
mMenge = rs.GetString("menge")
#If B4A Or B4i
memailtext = memailtext & CRLF & mMenge & " x " & mProdukt & ","
#Else
memailtext = memailtext & "%0A" & mMenge & " x " & mProdukt & "," 'Zeilenumbruch, 1x = %0A, 2x %0A%0A
#End If
Loop
rs.Close
#If B4i
Dim mailc As MailComposer
mailc.Initialize("mailc")
' mailc.SetToRecipients(Array("hello@example.com", "world@example.com"))
mailc.SetSubject("Einkauf" & " " & Main.mMarktProdukte)
mailc.SetBody(memailtext, False)
' create a file and add it as an attachment
' File.WriteString(File.DirTemp, "1.txt", "hello world")
' mailc.AddAttachment(File.DirTemp, "1.txt", "text/plain")
mailc.Show(B4XPages.GetNativeParent(B4XPages.GetPage("mainpage")))
#Else If B4A
Dim email As Email
email.To.Add("") '("xxx@xxx.com")
email.Subject = "Einkauf - " & Main.mMarktProdukte
email.Body = memailtext
' email.Attachments.Add(Starter.Provider.GetFileUri(FileName))
Dim in As Intent = email.GetIntent
in.Flags = 1 'FLAG_GRANT_READ_URI_PERMISSION
StartActivity(in)
#Else If B4J
Dim mMailAdress As String = "?" '"xxx@xxx.com"
Dim mMailSubject As String = "Einkauf" & "%20" & Main.mMarktProdukte 'Leerzeichen = %20
Fx.ShowExternalDocument("mailto:" & mMailAdress & "subject=" & mMailSubject & "&body=" & memailtext)
#End If
End Sub