Android Question Problems sending email with attachment

brodmuehler

Member
Licensed User
Longtime User
Hallo

I want to sent an email with an attachment from my app to my email account each time a certain sub is called by the user. The user itself does not need to recognised that the mail is being sent. Below are copies and extracts from the relevant subs.

The problem is now that with the specified attachment the email is not being sent, or at least I am not receiving anything. As soon as i try to sent the mail with the same settings without the attachment, it works.

Does someone have an idea what I am doing wrong?

Thanks again.
Regards
René

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim SQL1 As SQL
Dim DBFileName As String : DBFileName = "estartliste.sqlite"
Dim DBFileDir As String : DBFileDir = File.DirRootExternal & "/eStartliste"
Dim MyMail As SMTP
....

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

If FirstTime Then

' initialize the database
If File.Exists(DBFileDir, DBFileName) = False Then
File.MakeDir(File.DirRootExternal, "eStartliste")
File.Copy(File.DirAssets, DBFileName, DBFileDir, DBFileName)
End If
SQL1.Initialize(DBFileDir, DBFileName, True)

'Settings screen
CreatePreferenceScreen
If manager.GetAll.Size = 0 Then
SetDefaults
End If

'Email functionality through GMail
MyMail.Initialize("smtp.gmail.com", 465, "[email protected]", "Flight$1", "MyGmailSMTP")
MyMail.UseSSL = True

End If
....

Sub UploadFluege_Click

Dim JobUploadFluege As HttpJob
Dim jsonpost, q, s As String
Dim myJSON As JSONGenerator
Dim mp As Map

q = "SELECT * FROM starts Where Upload = 0 " & _
"AND Pilot1 <> '(0) Auswahl' " & _
"AND Start <> '00:00' " & _
"AND Landung <> '00:00'"
myJSON.Initialize(MyExecuteJSON_Upload(SQL1, q, Null, 0, _
Array As String(DB_INTEGER, DB_DATETIME, DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, _
DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, _
DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, DB_VARCHAR, _
DB_BOOL, DB_INTEGER, DB_INTEGER)))
s = myJSON.ToPrettyString(4)
'Msgbox(s, "")

ProgressDialogShow("Upload Flüge")
jsonpost="postjson=" & myJSON.ToString
JobUploadFluege.Initialize("JobUploadFluege", Me)
JobUploadFluege.PostString(urlUploadFluege, jsonpost)

Log("Email")
DateTime.DateFormat = "yyyy.MM.dd"
MyMail.To.Add("[email protected]")
MyMail.Subject = "eStartliste Database"
MyMail.Body = DateTime.Date(DateTime.Now)
MyMail.AddAttachment(DBFileDir, DBFileName)
MyMail.Send


End Sub
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi

i am using the same combination to send an database, but i made one step more: i first copied the database to a backup database and mailed the backup. Before backup i closed the database, made the copy and reopened it. So i had time to send the file and the user can work inside the original database without any waiting.
I used it as one type of backup place.
Greetings
Reinhard
 
Upvote 0

brodmuehler

Member
Licensed User
Longtime User
the database size is 288kB. Yes I handle the messagesend event but with the attachment i only get a timeexception message.

Not sure how to use the tags fpr code

[Sub MyGmailSMTP_MessageSent(Success As Boolean)

Log(Success)
If Success Then
ToastMessageShow("Message sent successfully", True)
Else
ToastMessageShow("Error sending message", True)
Log(LastException.Message)
End If

End Sub]
 
Upvote 0

brodmuehler

Member
Licensed User
Longtime User
Thanks for the explanation. Let's try ...

B4X:
Sub MyGmailSMTP_MessageSent(Success As Boolean)

Log(Success)
If Success Then
ToastMessageShow("Message sent successfully", True)
Else
ToastMessageShow("Error sending message", True)
Log(LastException.Message)
End If

End Sub
 
Upvote 0

brodmuehler

Member
Licensed User
Longtime User
is there any backside doing it as suggested by Rheinard .... closing the db, copying the db, reopening the db and sending the copy?
 
Upvote 0

brodmuehler

Member
Licensed User
Longtime User
I now tried the following, but without any success. The messagesend event is not triggered at all ....

B4X:
' Copy der DB an Mailadresse schicken - start
         Log("Email")
         If File.Exists(DBFileDir, DBFileNameBackUp) Then
           File.Delete(DBFileDir, DBFileNameBackUp)
         End If
         SQL1.Close
         File.Copy(DBFileDir, DBFileName, DBFileDir, DBFileNameBackUp)
         sb.Initialize
         DateTime.dateformat = "dd.MM.yyyy"
         DateTime.TimeFormat = "HH:mm:ss"
         sb.Append("Gesendet am: ").Append(DateTime.Date(DateTime.Now))
         sb.Append(CRLF)
         sb.Append("Gesendet um: ").Append(DateTime.Time(DateTime.Now))
         sb.Append(CRLF)
         MyMail.To.Add("[email protected]")
        MyMail.Subject = "eStartliste Database"
        MyMail.Body = sb
        MyMail.AddAttachment(DBFileDir, DBFileNameBackUp)
        MyMail.Send
         SQL1.Initialize(DBFileDir, DBFileName, True)
         ' Copy der DB an Mailadresse schicken - ende

any ideas? Thanks for any help.
René
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Hi,

i just tried my almost indentical routines; i sended a 5.3 Mb File and i worked; one tipp: you move your last row to the line after File.copy;
also check if you use the Net library version 1.37, i remember maybe some timeout problems with the version before.
If you want, you can make a sample program file an i try it at my place with my passwords...

Reinhard
 
Upvote 0
Top