Page 1 of 1

XML file attached in Gmail appears open in message body

Posted: Fri May 06, 2022 8:57 am
by PedroAlex
Hi, guys,

I have a problem that I don't see the reason for.

If I send an XML file as an attachment through a program written in xbase, the recipient receives the entire file open in the body of the email message and not as an attachment.

But if I send the same XML file as an attachment through Chrome/Gmail, the recipient correctly receives the file only as an attachment.

This only happens if the sending account is gmail. if I use another email from another service, this does not happen.

Does anyone know why this strange behavior occurs in gmail emails sent by xbase?
Has anyone had this problem?

Many Thanks?

Re: XML file attached in Gmail appears open in message body

Posted: Sat May 07, 2022 7:04 am
by rdonnay
Try changing the content-type.

oMail:setContentType('multipart/form-data')

Re: XML file attached in Gmail appears open in message body

Posted: Mon May 09, 2022 3:58 am
by PedroAlex
Roger,
I tried your suggestion but got the same result.
Does this happen with you too?

Re: XML file attached in Gmail appears open in message body

Posted: Mon May 09, 2022 4:30 am
by skiman
Hi Pedro,

I never noticed this problem when sending.

How is the attachment added? As a file?

I'm using Chilkat for sending mails, There is an oEmail:AddFileAttachment( cFile) to use.
With CDO it is something similar as oCdoMessage:AddAttachment(cFile).

I suppose there can be a difference as with images, they can be an atttachment, and they can be part of the mail. Maybe this is the same for your problem and the XML?

Re: XML file attached in Gmail appears open in message body

Posted: Mon May 09, 2022 10:24 am
by PedroAlex
Hi Chris,

here is sample code :

Code: Select all

//----------------------------------------------------------------------------------
Procedure SendMail_SMTP()
//----------------------------------------------------------------------------------
LOCAL oSmtp       := SMTPClient():new(  "smtp.gmail.com",465)
LOCAL oSender     := MailAddress():new( "fromemailadress@gmail.com" )
LOCAL oRecipient  := MailAddress():new( "toemailadress@gmail.com" )
LOCAL cAttachment := 'C:\File.xml'
LOCAL oMail       := MIMEMessage():new()
LOCAL cText       := "Anexed, file XML" 

//oMail:setContentType('multipart/form-data')
oMail:setContentType('application/xml')
oMail:setFrom     ( oSender     )
oMail:setSubject  ( "XML File attached" )
oMail:setMessage  ( cText       )
oMail:addRecipient( oRecipient  )
oMail:attachFile  ( cAttachment )

      IF oSmtp:connect( "fromemailadress@gmail.com", "cKeyApp" )

         IF oSmtp:send( oMail )
            MsgBox( "Message sent" )
         ELSE
            MsgBox( "Unable to deliver message" )
         ENDIF

         oSmtp:disconnect()

      ELSE

         MsgBox(  "Unable to connect to mail server" )

      ENDIF

   RETURN


Re: XML file attached in Gmail appears open in message body

Posted: Mon May 09, 2022 11:59 pm
by skiman
Hi,

Why are you doing this?

Code: Select all

oMail:setContentType('application/xml')
Have you tried it without this setting?

Re: XML file attached in Gmail appears open in message body

Posted: Fri May 13, 2022 1:14 am
by PedroAlex
Hi Chris,
Yes, I've tried other settings and it's the same.
Can you try with this code?
The problem only happens when the recipient opens gmail in the browser, eg. in Chrome.
I've already tested it with Chilkat and this problem doesn't happen.

Re: XML file attached in Gmail appears open in message body

Posted: Fri May 13, 2022 3:27 am
by skiman
Hi Pedro,

I'm using Chilkat, and because I don't have to set any contenttype, I was wondering if that could be the cause.

I never had a customer who had this complaint. Electronic invoices are send as XML, so if this would be a problem, customers would have reported this.

Any reason you don't use Chilkat? Since it looks you have it?

Re: XML file attached in Gmail appears open in message body

Posted: Sat May 14, 2022 3:20 am
by PedroAlex
Hi Chris,

This strange behavior does not stop the system from working. The XML file is sent as an attachment. It simply appears all open in the body of the email and only at the end of all this text is the link to download.
However, I repeat this situation only if the email received is consulted in gmail online.
If the received email is consulted for example in windows mail everything is OK.
I don't have Chilkat, I've been testing the 30 day version.
I always give preference to developing the needs in native xBase++ or with eXpress++.
But developing in xBase++ is getting difficult and expensive.
Chilkat is an excellent library and it seems to me that sooner or later I will have to buy it, because there are needs that xBase doesn't answer.
However I noticed that sending the email with xBase is much faster than sending it with Chilkat. with Chilkat it is necessary to establish a connection with the Activex component and perhaps this procedure will remove some application performance.