Posts: 5
Threads: 1
Joined: Oct 2021
Reputation:
0
Location: Michigan
Trying to send a email with pdf attachment. But when the email shows up in gmail, its just the raw uue text, and none of the email clients I've triled (gmail, smartermail, thunderbird) recognize the attachement. What could I be doing wrong?
Indy10, Delphi 2010
Thanks!
--Stan
Posts: 640
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
(10-18-2021, 07:36 PM)scampsmith Wrote: Trying to send a email with pdf attachment. But when the email shows up in gmail, its just the raw uue text, and none of the email clients I've triled (gmail, smartermail, thunderbird) recognize the attachement. What could I be doing wrong?
Please show the code you are using to setup the TIdMessage and then send it. Indy does not use UUE by default, it favors MIME instead. UUE was popular back in the old days of early email systems, and for posting on Usenet newsgroups, but it hasn't been widely used in a long time.
(10-18-2021, 07:36 PM)scampsmith Wrote: Indy10, Delphi 2010
Which version of Indy 10 are you using?
Posts: 6
Threads: 1
Joined: Jan 2020
Reputation:
0
Location: Australia
This works for me:
idmsg := TIdMessage.Create;
idmsg.Date := Now;
idmsg.FromList.EMailAddresses := FEmailReply;
idmsg.Subject := SubJect;
idmsg.Recipients.EMailAddresses := ReceiveAddr;
idmsg.ContentType := 'multipart/mixed';
IdDesc := TIdText.Create(idmsg.MessageParts,slInfo);
IdDesc.ContentType := 'text/html';
loAttachments := TObjectStringsList.Create;
for j := 0 to slFiles.Count-1 do
begin
idAttach := TIdAttachmentFile.Create(idmsg.MessageParts,slFiles[j]);
loAttachments.AddObject(slFiles[j],idAttach);
end;
if( Assigned(psInsideFiles))then
for j:=0 to psInsideFiles.Count-1 do
begin
idAttach := TIdAttachmentFile.Create(idmsg.MessageParts,psInsideFiles[j]);
loAttachments.AddObject(psInsideFiles[j],idAttach);
idAttach.ContentType := GetMIMETypeFromFile(psInsideFiles[j]);
loStringObj := TStringObj( psInsideFiles.Objects[j] );
idAttach.ContentDisposition := 'inline';
idAttach.ContentID := loStringObj.TheString;
end;
Posts: 640
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
10-19-2021, 12:44 AM
(This post was last modified: 10-19-2021, 12:45 AM by rlebeau.)
(10-19-2021, 12:05 AM)Robert Gilland Wrote: This works for me:
Why are you adding the attachments to both the TIdMessage and a TObjectStringsList?
In any case, you might consider using TIdMessageBuilderHtml to simplify the logic of populating the TIdMessage body, eg:
Code: idmsg := TIdMssage.Create;
try
idmsg.Date := Now;
idmsg.FromList.EMailAddresses := FEmailReply;
idmsg.Subject := SubJect;
idmsg.Recipients.EMailAddresses := ReceiveAddr;
idMsgBldr := TIdMessageBuilderHtml.Create;
try
idMsgBldr.Html.Assign(slInfo);
for j := 0 to slFiles.Count-1 do begin
idMsgBldr.Attachments.Add(slFiles[j]);
end;
if Assigned(psInsideFiles) then begin
for j := 0 to psInsideFiles.Count-1 do
idMsgBldr.HtmlFiles.Add(psInsideFiles[j], TStringObj(psInsideFiles.Objects[j]).TheString);
end;
idMsg := idMsgBldr.FillMessage(idMsg);
finally
idMsgBldr.Free;
end;
// use idMsg as needed...
finally
idMsg.Free;
end;
Alternatively:
Code: idmsg := nil;
try
idMsgBldr := TIdMessageBuilderHtml.Create;
try
idMsgBldr.Html.Assign(slInfo);
for j := 0 to slFiles.Count-1 do begin
idMsgBldr.Attachments.Add(slFiles[j]);
end;
if Assigned(psInsideFiles) then begin
for j := 0 to psInsideFiles.Count-1 do
idMsgBldr.HtmlFiles.Add(psInsideFiles[j], TStringObj(psInsideFiles.Objects[j]).TheString);
end;
idMsg := idMsgBldr.NewMessage;
finally
idMsgBldr.Free;
end;
idmsg.Date := Now;
idmsg.FromList.EMailAddresses := FEmailReply;
idmsg.Subject := SubJect;
idmsg.Recipients.EMailAddresses := ReceiveAddr;
// use idMsg as needed...
finally
idMsg.Free;
end;
Posts: 5
Threads: 1
Joined: Oct 2021
Reputation:
0
Location: Michigan
10-19-2021, 01:59 PM
(This post was last modified: 10-19-2021, 02:32 PM by scampsmith.)
Thanks, everyone!
Your responses helped me get it working on first try!
Using the TIdMessageBuilderHtml makes it super simple, unlike the demo project, which is what I based by original code from.
Thanks!
--Stanwood
Ooops! Spoke too soon! Then email looks better, but now the file is not actually transmitted. Even looking at the 'raw content' shows no MIM encoding, just the headers. I'm sure I'm still missing a step, since the original code I was using actualy did include the MIM encoding.
oMsg := TIdMessage.Create;
try
oMsg.Date := Now;
oMsg.FromList.EMailAddresses := Self.edtFrom.text
oMsg.Subject := edtSubJect.Text;
oMsg.Recipients.EMailAddresses := edtTo.Text;
oMsgBldr := TIdMessageBuilderHtml.Create;
try
oMsgBldr.Html.Text := 'HTML goes here!';
OMsgBldr.PlainText.Text := Memo1.Text;
for j := 0 to lbFiles.Items.Count-1 do
oMsgBldr.Attachments.Add(lbFiles.Items[j]);
oMsgBldr.FillMessage(oMsg);
finally
oMsgBldr.Free;
end;
SMTP.AuthType := satDefault; {Simple Login}
SMTP.Username := 'order@hiemstraoptical.com'; // SmtpServerUser;
SMTP.Password := 'orderdept'; // SmtpServerPassword;
{General setup}
SMTP.Host := Self.SmtpServerName;
SMTP.Port := 25; // SmtpServerPort;
{now we send the message}
SMTP.Connect;
try
SMTP.Send(oMsg);
finally
SMTP.Disconnect;
end;
finally
oMsg.Free;
end;
Posts: 640
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
(10-19-2021, 01:59 PM)scampsmith Wrote: Ooops! Spoke too soon! Then email looks better, but now the file is not actually transmitted. Even looking at the 'raw content' shows no MIM encoding, just the headers. I'm sure I'm still missing a step, since the original code I was using actualy did include the MIM encoding.
Can you be more specific? What does the raw email actually look like? Both in what TIdMessage actually generates (which you can get by calling TIdMessage.SaveTo...(), or by hooking up one of the TIdLog... components to the TIdSMTP.Intercept property), and what you see in the email client.
Also, since you are not providing an HTML-encoded version of your Memo content, why are you sending an HTML email at all? You could just send a plain-text email, ie by using TIdMessageBuilderPlain instead of TIdMessageBuilderHtml.
Also, please tell me you didn't post your server's actual login credentials to a public forum???
Posts: 5
Threads: 1
Joined: Oct 2021
Reputation:
0
Location: Michigan
Thanks. I switched to the 'Plain' message builder. The 'SaveToFile' gave me only this this (I'm assuming the acual attachment should be included, but it's clearly not):
From: "order@hiemstraoptical.com" <order@hiemstraoptical.com>
Subject: Testing
To: scampsmith@hiemstraoptical.com
MIME-Version: 1.0
Date: Tue, 19 Oct 2021 15:15:29 -0400
Content-Type: application/pdf;
name="Beilby.Rx_0001.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Beilby.Rx_0001.pdf"
Content-ID: <Beilby.Rx_0001.pdf>
Posts: 640
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
10-19-2021, 10:50 PM
(This post was last modified: 10-19-2021, 10:51 PM by rlebeau.)
(10-19-2021, 07:22 PM)scampsmith Wrote: The 'SaveToFile' gave me only this this (I'm assuming the actual attachment should be included, but it's clearly not)
Yes, it should be included. That output is very wrong, especially if you are including text alongside the attachment. It SHOULD look more like this instead:
Code: From: "order@hiemstraoptical.com" <order@hiemstraoptical.com>
Subject: Testing
To: scampsmith@hiemstraoptical.com
MIME-Version: 1.0
Date: Tue, 19 Oct 2021 15:15:29 -0400
Content-Type: multipart/mixed;
boundary="497g4jflA=_NV5HJ64xjgrj7VJHVqagsh3"
--497g4jflA=_NV5HJ64xjgrj7VJHVqagsh3
Content-Type: text/plain
Plain text here...
--497g4jflA=_NV5HJ64xjgrj7VJHVqagsh3
Content-Type: application/pdf;
name="Beilby.Rx_0001.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Beilby.Rx_0001.pdf"
Content-ID: <Beilby.Rx_0001.pdf>
<base64 data here...>
--497g4jflA=_NV5HJ64xjgrj7VJHVqagsh3--
You didn't answered my earlier question - which version of Indy 10 are you using exactly? Are you using the one that shipped with Delphi 2010, or have you upgraded to a more up-to-date version?
Posts: 5
Threads: 1
Joined: Oct 2021
Reputation:
0
Location: Michigan
Not sure how to tell the version of the entire install, but not the one shipped with Delphi, but TidSMTP.Version gives me 10.6.2.5451
As a band-aid (hopefully temporary), I'm just shelling out to SwithMail.exe (open source command-line sendmail), but I'd rather not have so many moving parts.
--Thanks!
Stanwood
Posts: 640
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
(10-20-2021, 12:21 PM)scampsmith Wrote: Not sure how to tell the version of the entire install, but not the one shipped with Delphi, but TidSMTP.Version gives me 10.6.2.5451
That is indeed the version for the entire Indy library. However, that version is over 3 years old, so you should consider upgrading to the latest version from Indy's GitHub repo and see if the problem still happens. Though, I can't imagine why it would have ever been so broken to begin with, as TIdMessage, TIdMessageClient, and TIdMessageBuilder are quite mature classes.
|