[If it was possible to offer a Bounty, I would offer 200 points for this one.]

How do I successfully attach a file when sending an email via gmail in version

First, here are the results of my tests...

Test 1: Message sent to @recipient = bcarter@bcarter.com and received OK, but 
the attachment is garbled in Microsoft Outlook...

test subject at 2011-04-05 14:11:57.148
Foxhound <breck.carter@gmail.com>
Tue 4/5/2011 2:12 PM
attachment.txt (140 B)

Test 2: Message sent to @recipient = Breck.Carter@gmail.com and received OK, but 
Google Mail refuses to display attachment...

from    Foxhound <breck.carter@gmail.com>
to  Breck.Carter@gmail.com
date    Tue, Apr 5, 2011 at 2:15 PM
subject test subject at 2011-04-05 14:15:50.824
mailed-by   gmail.com
    Important mainly because it was sent directly to you.
hide details 2:15 PM (0 minutes ago) 
test message at 2011-04-05 14:15:50.824
Oops... the virus scanner has a problem right now. Download at your own risk, or try again later.
1K   View   Download    
Temporary Error (500)   
We’re sorry, but your Gmail account is temporarily unavailable. We apologize for the inconvenience and suggest trying again in a few minutes.
If the issue persists, please visit the Gmail Help Center »
Try Again Sign Out
Show Detailed Technical Info
Numeric Code: 54

Test 3: Attempts to send @include_file = 'c:\\temp\\attachment.zip' fail...

xp_startsmtp @return_code = 0
xp_sendmail @return_code = 104
Execution time: 2.487 seconds

Here is the attachment.txt file...

This is line 1 of 2 in attachment.txt.
This is line 2 of 2 in attachment.txt.

Here is the code used for Test 1, and modified as discussed above for Tests 2 and 3 (the smtp auth password value is not shown); this code DOES work when the attachment is omitted:

DECLARE @return_code           INTEGER;
DECLARE @smtp_sender           LONG VARCHAR;
DECLARE @smtp_server           LONG VARCHAR; 
DECLARE @smtp_port             INTEGER; 
DECLARE @timeout               INTEGER;
DECLARE @smtp_sender_name      LONG VARCHAR;
DECLARE @smtp_auth_username    LONG VARCHAR; 
DECLARE @smtp_auth_password    LONG VARCHAR;
DECLARE @trusted_certificates  LONG VARCHAR;
DECLARE @recipient             LONG VARCHAR;
DECLARE @subject               LONG VARCHAR;
DECLARE @message               LONG VARCHAR;
DECLARE @include_file          LONG VARCHAR;

SET @smtp_sender          = 'Breck.Carter@gmail.com'; -- full email address for gmail
SET @smtp_server          = 'smtp.gmail.com';  -- smtp.gmail.com for gmail
SET @smtp_port            = 587;  -- 25 for standard SMTP, 465 or 587 for gmail
SET @timeout              = 10;   -- default is 60 seconds
SET @smtp_sender_name     = 'Foxhound';
SET @smtp_auth_username   = 'Breck.Carter@gmail.com'; -- full email address for gmail
SET @smtp_auth_password   = '...';
SET @trusted_certificates = 'c:\\temp\\equifax.cer';
SET @recipient            = 'bcarter@bcarter.com';
SET @subject              = STRING ( 'test subject at ', CURRENT TIMESTAMP );
SET @message              = STRING ( 'test message at ', CURRENT TIMESTAMP );
SET @include_file         = 'c:\\temp\\attachment.txt';

@return_code = CALL xp_startsmtp ( 
   smtp_sender          = @smtp_sender,  
   smtp_server          = @smtp_server,  
   smtp_port            = @smtp_port,  
   timeout              = @timeout,
   smtp_sender_name     = @smtp_sender_name,
   smtp_auth_username   = @smtp_auth_username, 
   smtp_auth_password   = @smtp_auth_password,
   trusted_certificates = @trusted_certificates );

MESSAGE STRING ( 'xp_startsmtp @return_code = ', @return_code ) TO CLIENT;

@return_code = CALL xp_sendmail ( 
   recipient     = @recipient,  
   subject       = @subject,  
   "message"     = @message,
   include_file  = @include_file );

MESSAGE STRING ( 'xp_sendmail @return_code = ', @return_code ) TO CLIENT;

CALL xp_stopsmtp(); -- do not bother to check return code

   CALL xp_stopsmtp();


asked 02 Apr '11, 12:25

Breck%20Carter's gravatar image

Breck Carter
accept rate: 20%

edited 05 Apr '11, 14:38

Comment Text Removed
Comment Text Removed

This was caused by a bug in the code that encoded the attachment. Some mail readers would detect the invalid characters in the encoding and remove them, thereby allowing themselves to decode it, but others wouldn't so the attachment simply showed up as corrupted (which it was).

This will be fixed in builds,, and

P.S. I'm an administrator so I will simply bump my own rep by 200 and decrease Breck's by 200, thereby giving me the bounty he was offering. :-)

permanent link

answered 08 Apr '11, 11:39

Graeme%20Perrow's gravatar image

Graeme Perrow
accept rate: 54%

edited 08 Apr '11, 11:41

So you say we should now use the phrase "If I only could offer a bounty I'd give a thousand points" with care? :)

(08 Apr '11, 12:04) Volker Barth

Breck, I think you are going to slap yourself when you read this ... I tried your sample code (changing the gmail settings appropriately), and changed the include file to have the backslashes doubled-up. I.e.

SET @include_file         = 'c:\\temp\\attachment.txt';

and it worked perfectly. So you just need to make sure that the attachment pathname is correct :-)

permanent link

answered 05 Apr '11, 13:54

Mark%20Culp's gravatar image

Mark Culp
accept rate: 41%

edited 05 Apr '11, 14:07

Ooops, the single backslashes were the result of a desperate attempt to "try anything". I have re-tested with double-backslashes, and reposted both the code and the fresh (but otherwise identical) results.

FWIW this is using a fresh empty 32-bit network server running on Windows 7. I tried saving the attachment in Windows 7 and XP versions of Wordpad, and via Windows 7 Notepad as ANSI, Unicode, Unicode big-endian and UTF-8... all same results.

Did all three tests work for you, using Outlook and Gmail and the zip attachment?

It feels like a mime type issue to me... but I stand Ready To Slap Myself!

(05 Apr '11, 14:22) Breck Carter
Replies hidden

BTW... if the backslashes were an issue, why would Outlook receive anything at all? ( slap slap slap :)

(05 Apr '11, 14:39) Breck Carter
Replies hidden

Ah, I see. I had only sent an email through gmail to my corporate email address and read it using "wonderful" Lotus Notes.... and it worked fine.

Trying to read the email in gmail shows the same issues that you are seeing ("Oops.... the virus scanner has a problem..." and failed to read the attachment).

(05 Apr '11, 15:14) Mark Culp

I remember Lotus Notes! ...I also remember having to reach behind my computer to turn it on :)

(05 Apr '11, 15:44) Breck Carter

The cause of your problem is apparently more than just the missing backslashes, and its going to take a little more effort to figure out why the presence of the attachment is causing Gmail and Outlook to hiccup. I'll see what I can do - it'll take some mroe experimentation (and strategic logging of the smtp content) to figure out the exact cause.

(06 Apr '11, 15:19) Mark Culp

I've tracked down a bug in the code that adds the attachment to the SMTP email which, once corrected, will fix this issue. The fix will be included in a future EBF. Thanks for pointing out the issue.

(07 Apr '11, 12:38) Mark Culp
showing 3 of 6 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 02 Apr '11, 12:25

question was seen: 12,226 times

last updated: 08 Apr '11, 14:40