Jump to content
bazzer747

Attachments to iPhones

Recommended Posts

I send many emails out which have PDF attachments and usually via Outlook. However, I also provide the ability to send the same emails with the same PDF attachments via Indy.

 

If the emails go to a Windows PC, or to an Android mobile they arrive correctly and the PDF attachment can be opened and viewed correctly. However, when these same emails go to iPhones the PDF shows as an attachment to the email but cannot be opened. Except if the iPhone is an old model and not at the latest version it can open PDFs from the email.

 

Is this a known issue, or maybe a problem that Indy is aware of and can provide a solution?

Share this post


Link to post

google this "emails go to iPhones the PDF shows as an attachment to the email but cannot be opened"

thinking, probably not Indy to blame.

Share this post


Link to post

I agree, this does not sound like an Indy issue, especially since the PDFs can be opened on older iPhones without changing the Indy code.  But, this does not necessarily negate the possibility that the emails might not be getting setup correctly to begin with, and perhaps newer iPhones are just less lenient on mistakes than older iPhones?

 

Can you please show the actual code you are using? And what the raw data of the emails actually looks like?

 

Also, are you having the same problem when sending the emails via Outlook to iPhone?  If not, then I suggest you compare the raw data of Outlook's email to Indy's emails to see what is different between them.

Edited by Remy Lebeau

Share this post


Link to post

Thanks, qubits, I've Googled this and there's a mass of items about issues with PDFs sent to iPhones. Most talk of the obvious, like corrupt PDFs or incompatible formats and lots from way back. Trying to figure which if any relate to my issue is difficult, but I'll pursue. 

 

Remy, I can send the same email (with a PDF attached) from Outlook or from Indy to myself on a PC and on an Android phone (a gmail account) and they arrive OK with the attachment which I can open OK. Here is the gist of the code which I use:

 

procedure CreateIndyEmail( xMsg:string; xFirstName:string; xNameid:integer; xEmail: String; xSubject:string );
var
  DATA: TIdMessage;
  SMTP: TIdSMTP;
  SSL:  TIdSSLIOHandlerSocketOpenSSL;
begin
DATA:= TIdMessage.Create(nil);
with DATA do
  begin
    Clear;
    ContentType := 'text/html';
    ContentType := 'multipart/mixed';
    Subject     := xSubject;
  end;
IdOpenSSLSetLibPath( cLoc );
SSL:= TIdSSLIOHandlerSocketOpenSSL.Create(nil);
With SSL do
  begin
    Destination           := 'smtp.xxvemail.co.uk';
    Host                  := 'smtp.xxvemail.co.uk';
    SSLOptions.Mode       := sslmClient; // was sslmUnassigned;
    Port                  := 587;  //465; ;
    SSLOptions.Method     := sslvTLSv1_2;   // originally sslvTLSv1; Fasthosts suggeted change
    SSLOptions.Mode       := sslmUnassigned;
    SSLOptions.VerifyMode := [];
    SSLOptions.VerifyDepth:= 0;
  end;
SMTP:= TIdSMTP.Create(nil);
with SMTP do
  begin
    IOHandler            :=  SSL;
    UseTLS               :=  utUseExplicitTLS;
    Host                 := 'smtp.livemail.co.uk';
    Port                 :=  587; 
    AuthType             :=  satDefault;
  end;
DATA.Recipients.EMailAddresses:= xEmail;
SMTP.password              := 'xyz';
SMTP.username              := 'Seniors@xyz.com';
DATA.From.Address          := 'Seniors@xyz.com';
DATA.Sender.Address        := 'Seniors@xyz.com';
DATA.ReplyTo.EMailAddresses:= 'Seniors@xyz.com';
with TIdMessageBuilderHtml.Create do
  try
    Html.Text := xMsg;
    if gvbAttached = True then HtmlFiles.Add( gvAttachedFile );
    FillMessage( DATA );
  finally
    Free;
  end;
try
  SMTP.Connect;
  SMTP.Send( DATA );
finally
  SMTP.Disconnect;
end; 

Share this post


Link to post
2 hours ago, bazzer747 said:

Remy, I can send the same email (with a PDF attached) from Outlook or from Indy to myself on a PC and on an Android phone (a gmail account) and they arrive OK with the attachment which I can open OK.

But, can you send a PDF from Outlook to iPhone and open it OK?  If not, then this is an iPhone issue, otherwise this is an Indy issue.

2 hours ago, bazzer747 said:

Here is the gist of the code which I use:

Just a few comments:

  • You are (potentially) leaking the Indy objects (other than the MessageBuilder).  You did not say which version of Delphi you are using, but I'm assuming it is an older version where FMX still relied on ARC memory management for objects on mobile platforms.  That ARC system was removed in Delphi 10.4, so if you are (or ever will be) using 10.4 or later, you need to Free() unowned objects manually to avoid leaks.
  • You are setting the TIdMessage.ContentType property 3 times, which is (obviously) redundant. Let the TIdMessageBuilderHtml populate the TIdMessage with the bulk of its settings as needed (including the ContentType), then you can provide the rest (Sender, Recipients, Subject, etc).
  • The TIdMessageBuilderHtml.HtmlFiles property is meant for attachments that are referenced by the HTML (images, etc).  So, unless you are displaying the PDF embedded in the HTML, non-HTML attachments that the user can download and save should be in the TIdMessageBuilderHtml.Attachments property instead.
  • You don't need to set the SSLIOHandler's Destination, Host, or Port properties manually, Connnect() will handle that for you.
  • I would suggest using the SSLIOHandler's SSLVersions property instead of its Method property.  Not all servers require TLS 1.2 yet, so you should also enable TLS 1.1 at least.
  • Connect() should be outside of the try/finally that calls Disconnect()

Try this:

procedure CreateIndyEmail( const xMsg: string; const xFirstName: string; xNameid: integer; const xEmail: string; const xSubject: string );
var
  DATA: TIdMessage;
  SMTP: TIdSMTP;
  SSL:  TIdSSLIOHandlerSocketOpenSSL;
begin
  DATA := TIdMessage.Create(nil);
  try
    with TIdMessageBuilderHtml.Create do
    try
      Html.Text := xMsg;
      //if gvbAttached then HtmlFiles.Add( gvAttachedFile );
      if gvbAttached then Attachments.Add( gvAttachedFile );
      FillMessage( DATA );
    finally
      Free;
    end;
    DATA.Subject               := xSubject;
    DATA.From.Address          := 'Seniors@xyz.com';
    DATA.Sender.Address        := 'Seniors@xyz.com';
    DATA.ReplyTo.EMailAddresses:= 'Seniors@xyz.com';
    DATA.Recipients.EMailAddresses := xEmail;

    SMTP := TIdSMTP.Create(nil);
    try
      with SMTP do
      begin
        UseTLS               :=  utUseExplicitTLS;
        Host                 := 'smtp.livemail.co.uk';
        Port                 :=  587; 
        AuthType             :=  satDefault;
        Username             := 'Seniors@xyz.com';
        Password             := 'xyz';
      end;

      IdOpenSSLSetLibPath( cLoc );
      SSL := TIdSSLIOHandlerSocketOpenSSL.Create(SMTP);
      with SSL do
      begin
        SSLOptions.Mode         := sslmClient;
        SSLOptions.SSLVersions  := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
        SSLOptions.VerifyMode   := [];
        SSLOptions.VerifyDepth  := 0;
      end;
      SMTP.IOHandler := SSL;
      
      SMTP.Connect;
      try
        SMTP.Send( DATA );
      finally
        SMTP.Disconnect;
      end;
    finally
      SMTP.Free;
    end;
  finally
    DATA.Free;
  end;
end;

 

  • Like 1

Share this post


Link to post

Many thanks for  taking the time to help with this issue. I've changed my code to reflect what you are suggesting so again thanks for explaining that. I pick up bits and pieces from different places and sometimes they do end up a bit haphazard. Forget the attachment, it was early in changing the code, I had a create in the wrong place.

 

This is the first time my User has used Indy to send emails with attachments (as he doesn't have Outlook), previously all emails with attachments have been sent by Outlook. And these have been sent to iPhone, Android mobiles, PCs etc. with no problems. From that it would appear to be an Indy issue, would you agree? Although I have one User, who has an old iPhone (with an older version of iOS) who receives these messages and can open the PDFs OK. That would indicate a later iOS might have something to do with the problem.

 

 

AccessViolation.jpg

Share this post


Link to post

Done some further testing. The emails with PDF attachments can be opened and read on iPhone/iOS version 14.7.1. I also had someone with iOS 15.3.1 who could open a PDF OK. It seems those with iOS 15.4 are the ones having the problem. In the UK that was released March 14th.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×