SMTPSocket fails to send file on Windows

Hello Everyone,

On my Windows 8.1 machine I am able to send text emails to my hotmail.com account. An additional five lines of code (see code) for the email attachment cause the SMTPSocket to time out when trying to send an attachment (jpg less than 150 kb). When I run this on my Mavericks Yosemite machine I am able to send a simple and small text file.

[code] 'Create the connection
'SMTPSocket1.Secure = True
SMTPSocket1.Address = TFSMTPProvider.Text 'SMTP Address
SMTPSocket1.Port = Val(TFSMTPPort.Text) 'Port number
SMTPSocket1.Username = TFSMTPUser.Text 'Email address
SMTPSocket1.Password = TFSMTPPassword.Text 'Email password

'Assemble the email details
Dim Mail as new EmailMessage
Mail.FromAddress = TFSMTPUser.Text 'Email ‘from’ address
Mail.Subject = TFSMTPSubject.Text 'Subject line of email
Mail.BodyPlainText = TFSMTPMessage.Text 'The email message
Mail.Headers.AppendHeader(“X-Mailer”,“Example”) 'Not manditory for hotmail

'Sending email to…
Mail.AddRecipient(TFSMTPUser.Text)

Dim file as new EmailAttachment 'these five lines don’t seem to work
'file.ContentEncoding=“Base64”
'file.MIMEType=“image/jpeg”
file.LoadFromFile(f)
Mail.Attachments.Append(file)

'Add details to the email
SMTPSocket1.Messages.Append(Mail)

'Send the complete email
SMTPSocket1.SendMail[/code]

When I run the example program in xojo (Email Example.xojo_binary_project), I get an error that mentions:

Any helpful thoughts? Possibly modify the Email example supplied by Xojo?

Is this new to 2014r3.1?

Hi Joe,

I tried this on 2014 r3 and it does the same thing there. It doesn’t look new to 2014 r3.1

Have had fun with starttls in the last weeks, too, but only for Imap. Normally, you start non-secure and then do the starttls command.

Thanks Beatrix,

I will give it a try later today. :slight_smile:

[quote=152444:@Eugene Dakin]On my Windows 8.1 machine I am able to send text emails to my hotmail.com account. An additional five lines of code (see code) for the email attachment cause the SMTPSocket to time out when trying to send an attachment (jpg less than 150 kb). When I run this on my Mavericks Yosemite machine I am able to send a simple and small text file.
[/quote]

A shot in the dark as I am ignorant in this area … but try:

'Create the connection SMTPSocket1.Secure = True SMTPSocket1.ConnectionType = SSLSocket.TLSv12 'etc

Maybe they newer protocol will be less fussy

SMTPSecureSocket uses STARTLS by default. In 2014r3, you can switch to SSL/TLS if necessary.

By the way, are you using SMTPSocket or SMTPSecureSocket?

@Karen Atkocius, Thank you for trying. Text emails work well, but attachments don’t seem to send.

@Greg O’Lone, the program is SMTPSecureSocket

Attached is an example program.

Example7-3.zip Download

The Send No Attachment pushbutton code successfully sends a text email when a valid SMTP user (eg. me@hotmail.com) with a SMTP password (eg. 12345) is added.

To try and send an email with an attachment, add a valid SMTP user and SMTP password, and press the Add Attachment pushbutton and add a small file such as a jpg. Press the Send With Attachment button and the email hangs.

Settings for hotmail SMTP are at: Hotmail SMTP Settings

Thanks for your help in trying to figure this out. :slight_smile:

just out of curiosity, have you tried changing the SMTPConnectionMode to SSLTLS?

Just tried it with SMTPConnectionMode to SSLTLS and the program was not able to send a text email nor a text email with attachment. It was worth a try :slight_smile:

An attachment doesn’t make any difference at all. The content of a mail is just text. Except if sending mails with attachments is blocked at the recipient or attachments are fished out by enterprise IT.

starttls is initiated with a non-secure connection and won’t work with a secure one.

I don’t have a Hotmail account. Is there a difference to Office 365 Exchange? Got one of these for testing.

The first thing to try is to use port 587 instead of 25.

Something else to consider. How big is the file you are trying to attach? File attachments are Base64Encoded, so the sending size goes up a bit. Could it be that the attachment is going over the Hotmailattachment limit?

Thanks for the help. On both port 25 and 587 the email works with no attachment. When there is an attachment the Xojo program hangs.

Hi Greg. I don’t think I am over the limit. I tried to send a jpg file (148 kb), and the zipped file of the jpg image (144 kb).

[code] 'Create the connection
SMTPSocket1.Secure = True
SMTPSocket1.ConnectionType = SSLSocket.TLSv12
SMTPSocket1.Address = TFSMTPProvider.Text 'SMTP Address
SMTPSocket1.Port = Val(TFSMTPPort.Text) 'Port number
SMTPSocket1.Username = TFSMTPUser.Text 'Email address
SMTPSocket1.Password = TFSMTPPassword.Text 'Email password

'Assemble the email details
Dim Mail as new EmailMessage
Mail.FromAddress = TFSMTPUser.Text 'Email ‘from’ address
Mail.Subject = TFSMTPSubject.Text 'Subject line of email
Mail.BodyPlainText = TFSMTPMessage.Text 'The email message
Mail.Headers.AppendHeader(“X-Mailer”,“Example”) 'Not manditory for hotmail

'Sending email to…
Mail.AddRecipient(TFSMTPUser.Text)

'Added three lines for file attachment
Dim file as new EmailAttachment
file.LoadFromFile(f)
Mail.Attachments.Append(file)

'Add details to the email
SMTPSocket1.Messages.Append(Mail)

'Send the complete email
SMTPSocket1.SendMail[/code]

If the three lines for file attachment are deleted or commented out, then the program sends text properly on both port 25 and port 587.

The SMTPConnectionMode must be STARTTLS (SSL/TLS will not send a text message or attachment). Funny thing is the Windows Settings link shows that for a POP3 and SMTP account both SSL and TLS should work.

Thanks for your patients and for trying to help :slight_smile:

Ok, I think I found a bug…

When I subclassed SMTPSecureSocket, attachments would not go through on Windows. When I created a SMTPSecureSocket object, the attachment goes through on Windows 8.1.

<https://xojo.com/issue/37375>

Beatrix and Greg, thank you for your help!

So your socket was going out of scope? That would explain why small emails went through but large ones did not. The small ones had enough time to finish, but not the large ones.

Hi Tim,

I am not sure what you mean by going out of scope (but I am willing to learn :slight_smile: ). My guess is that there may be something in the SecureServerSocket that might have been missed underneath the hood.

Both SSL/TLS and STARTTLS SMTPConnectionModes work on the object, while the subclass only allows STARTTLS to work.

Is this what is mean’t by out-of-scope?

That there were no references to the object left before code could execute so the framework destroys the by releasing the memory the object used.

Thanks Karen and Tim! Its always good to learn at least one new thing a day.

Eugene