Email attachment problem

Hi:

I am trying to send an email with an attachment. I am using the Email Example program from Xojo’s Communications folder under their Example Apps. I can easily send an email, but when I try to send an 120 kb attachment it does not get sent. All that shows up for the attachment is a file named Part 1.2 and it is 1 byte in size. Here is my relevant code:

file = New emailAttachment
file.MIMEType = “application/pdf”
file.LoadFromFile GetFolderItem("/Users/stravis/Desktop/test.pdf")
mail.Attachments.Append file

Any help or thoughts would be appreciated.

did you debug it?
maybe the attachment object has no data as file path is wrong?

Yes, I did debug it.

I have verified the path by going to the terminal, changing to the file’s directory, and then using the pwd command. The attachment document is a 120 kb file. I opened it with Adobe to be sure.

You can try

dim myfile as Folderitem = GetFolderItem("/Users/stravis/Desktop/test.pdf", FolderItem.PathTypeNative) if myfile <> nil and myfile.exists then file = New emailAttachment file.MIMEType = "application/pdf" file.LoadFromFile (myfile) mail.Attachments.Append file else MSGBox "Error myfile" end if

or use SpecialFolder.Desktop.Child(“test.pdf”)

Axel:

Your code worked once I replaced the GetFolderItem with the SpecialFolder code you suggested.

Do you have any ideas why the GetFolderItem won’t work? I have verified the path, and I know the file is not “nil”. It is also interesting that Xojo’s example program does not work with an attachment.

Thanks.

Now, I have migrated the code to an app that is to be deployed to Xojo’s cloud. I know that the file is successfully being attached.

As per a suggestion from Jason P. (Xojo support) I opened a firewall port. That too is successful.

But yet no email is sent.

Also, I just checked my SMTPSocket after SendMail command, and I get an error 102. 102 is a lost connection error.

some time ago I had extended the example to test some things with SMTPSecureSocket.
maybe it helps. (fill pop.Change with your account settings)

Download

Look in the ServerError event. The ErrorMessage property should tell you why it’s complaining.

By the way, you should be using an SMTPSecureSocket out on the net.

FWIW, you will still get a 102 Disconnect even if the send is successful. I suggest subclassing SMTPSecureSocket and logging all of the events just to be sure that it’s doing what you expect.