Hi,
i sent an e-mail from my xojo-app with adding an attachment. works fine now. but somtimes the attachment is displayed as symbol in mail.app and sometimes there is only a ?-sysmbol. the file is ok, i can open it via double-click and preview opens and show the proper pdf-file.
Here’s the code i use to send the mail:
[code] Dim sendMailSocket As New SMTPSecureSocket
Dim mail As New EmailMessage
Dim file As New EmailAttachment
sendMailSocket.Address = “my-mail-server”
sendMailSocket.Secure = True
sendMailSocket.Username = “my-username”
sendMailSocket.Password = “my-pasword”
if cbxAttachment.State = CheckBox.CheckedStates.Checked then
Dim fileToAttach As FolderItem
fileToAttach = GetOpenFolderItem(“application/pdf”)
file.LoadFromFile(GetFolderItem(fileToAttach.NativePath, FolderItem.PathTypeShell))
mail.Attachments.Append(file)
end if
mail.FromAddress = txtSender.Text
mail.Subject = txtSubject.Text
mail.BodyPlainText = TextArea1.Text
mail.AddRecipient(txtReceiver.Text)
sendMailSocket.Messages.Append(mail)
sendMailSocket.SendMail[/code]
Can i control by code how the attachment is embedded in my mail?
Michael
You forgot the name of the attachment. For instance:
dim theAttachment as new EmailAttachment
theAttachment.LoadFromFile(tempFile)
theAttachment.Name = "CrashLogs.gz"
theAttachment.MIMEType = "application/gzip"
Thanks Beatrix. This seems to work. Will try it on windows also.
Michael
Seems to work on windows and mac. Now there remains a problem, that german-umlauts in the attachment-name are not correctly encoded. How can i realize, that after Subject and Body, now also the attachment-name is display with correct umlauts?
Michael
[quote=168997:@Michael Bzdega]<…> Now there remains a problem, that german-umlauts in the attachment-name are not correctly encoded. How can i realize, that after Subject and Body, now also the attachment-name is display with correct umlauts?
Michael[/quote]
One of the many things that do ALMOST work in Xojo…
If you want it to work, you have to use MBS plugins.
See here: https://www.monkeybreadsoftware.net/class-curlemailmbs.shtml
You can test the plugins without having to buy a license. Download the plugins, put them to the Xojo plugins folder and then try out the “Send email.xojo_binary_project” sample from its /Examples/CURL/Send Email/ folder.
It solves the Umlaut issue plus it shows how to use a thread and timer to perform a safe sending of mails with attachments.
hmm… thanks for this suggestion. would love to realize this without plugins… i will have a look at the mbs plugins.
Michael
Without plugins, if this is acceptable, you could simply remove the accents with
theAttachment.Name = ConvertEncoding("Rückumlaut.doc", Encodings.ASCII)
How do the umlauts show up? The attachments should have their encoding in front of the name. Here is an example that I found in my code: =UTF-8’'License%3D%CC%B8Agreement.rtf (there might be an "= at the end that is already cut off). You could also send yourself an attachment with an umlaut to see how the mail client handles this.
The attachment name is url encoded, by the way.
[quote=169034:@Michel Bujardet]Without plugins, if this is acceptable, you could simply remove the accents with
theAttachment.Name = ConvertEncoding("Rückumlaut.doc", Encodings.ASCII)
This gives me an attachment.name like this: “Ru?eckumlaut.doc”.
it simply would be ok, if i could convert the umlauts to ae, oe, ue, you know. Tried this with replaceall, but couldn’t get it running.
attachment.name = ReplaceAll(attachment.Name, "", "ae")
but the attachment.name still contains the .
if i use a fixed string, the replaceAll works:
attachment.name = ReplaceAll("some-string", "", "ae")
Whats wrong with my replaceAll?
I do not understand. This
msgbox ConvertEncoding("Rückumlaut.doc", Encodings.ASCII)
shows as “Ruckumlaut”
Are you sure you have used encodings.ASCII ? I do not see how pure ASCII like this can suddenly turn into some Unicode text gibberish.
Could you place this after the line where you set attachment.name
to verify the actual value of your variable :
system.debuglog attachment.name
Then you can see the message by clicking the third icon at the bottom of the IDE while your app runs.
The description how the encoding should be is here: http://tools.ietf.org/html/rfc2231 . Very dry stuff. But the example I gave was correct.
I placed the system.debuglog-statement into my code and got this without using ConvertEncoding:
geschftsverlauf-06-09-2014.pdf
And with ConvertEncoding i get this:
gescha?ftsverlauf-06-09-2014.pdf
Are you sure you are using
theAttachment.Name = ConvertEncoding(filename, Encodings.ASCII)
Would you be so kind to post the code ?
[code] if mailHasAttachment = True then
Dim dlg As New OpenDialog
Dim f As FolderItem
dlg.Title = "Bitte Anhang auswhlen..."
f = dlg.ShowModal
if f <> NIL then
System.DebugLog f.Name
attachment.LoadFromFile(GetFolderItem(f.NativePath, FolderItem.PathTypeNative))
'attachment.name = ReplaceAll(f.Name, "", "ae")
attachment.name = ConvertEncoding(f.Name, Encodings.ASCII)
system.debuglog attachment.name
mail.Attachments.Append(attachment)
end if
end if[/code]
Any ideas why my replaceAll is not working?
I just tried this :
dim f as FolderItem = GetOpenFolderItem("special/any")
dim name as string
name = ConvertEncoding(f.Name, Encodings.ASCII)
system.DebugLog name
I created a file called “geschftsverlauf-06-09-2014” and picked it.
I get geschaftsverlauf-06-09-2014.pdf
You must have a gremlin in your 'puter if it does anything else. I give up.
I am starting to suspect you are switching variables somewhere in your code, and the change is never taken into account. That is the only valid reason why your replaceall or the convertencoding does not work.
no, it’s an iMac. must be a very slim gremlin.
Michel, do you have any suggestions to my replaceAll-Problem?
I had a doubt so I tried on a Mac, when the string is in ASCII, I see absolutely no way it can produce something like what you tell me.
After your replaceall, attachment.name
should be
geschaeftsverlauf-06-09-2014.pdf
I would start by placing something like
msgbox attachment.name
right after the replaceall
If it still produces gescha?ftsverlauf-06-09-2014.pdf I recommend an exorcist