Thread View: borland.public.cppbuilder.internet.socket
11 messages
11 total messages
Started by Royce Fessenden
Thu, 06 Sep 2007 16:53
Attachment missing from email
Author: Royce Fessenden
Date: Thu, 06 Sep 2007 16:53
Date: Thu, 06 Sep 2007 16:53
42 lines
2180 bytes
2180 bytes
I am trying to add the ability to email error logs from the help screen of an application. I have a simple test form with a TIdSMTP component and a TIdMessage component. I can send an email but I can't get the attachment to be included. I'm using the following test code in Borland C++ Builder 6, using Indy 9.0.50.
int TMainForm::TestFunction(void)
{
AnsiString FileToAttach = "C:\\Link\\Logs\\Logs.zip";
if (FileExists(FileToAttach))
{
Log->Lines->Add("Attaching file " + FileToAttach);
}
else
{
Log->Lines->Add("File <" + FileToAttach + "> does not exist.");
}
TDMPCursor MyCursor(crHourGlass);
// MailMessage is a TIdMessage component on the main form.
MailMessage->ContentType = "multipart/related; type=\"text/html\"";
MailMessage->Body->Add("With attachment.");
TIdAttachment* LogFile = new TIdAttachment(MailMessage->MessageParts, FileToAttach);
LogFile->FileName = FileToAttach;
//LogFile->ContentType = GetMIMETypeFromFile(LogFile->FileName);
LogFile->ContentType = "application/zip";
try
{
// SMTPClient is a TIdSMTP component on the main form.
SMTPClient->Connect();
SMTPClient->Send(MailMessage);
}
__finally
{
SMTPClient->Disconnect();
}
Log->Lines->Add("TestFunction Completed: " + AnsiString(""));
return 0;
}
What am I missing?
Royce
Re: Attachment missing from email
Author: Remy Lebeau (TeamB)
Date: Thu, 06 Sep 2007 18:19
Date: Thu, 06 Sep 2007 18:19
50 lines
2300 bytes
2300 bytes
"Royce Fessenden" <rfessenden@dmp.com> wrote in message
news:46e03084$1@newsgroups.borland.com...
> I can send an email but I can't get the attachment to be included.
That is because you are putting the text in the wrong place and setting the
wrong ContentType for the message. Try this instead:
int TMainForm::TestFunction(void)
{
AnsiString FileToAttach = "C:\\Link\\Logs\\Logs.zip";
if( !FileExists(FileToAttach) )
{
Log->Lines->Add("File <" + FileToAttach + "> does not exist.");
return -1;
}
Log->Lines->Add("Attaching file " + FileToAttach);
TDMPCursor MyCursor(crHourGlass);
MailMessage->ContentType = "multipart/mixed";
TIdText *txt = new TIdText(MailMessage->MessageParts, NULL);
txt->Body->Add("With attachment.");
txt->ContentType = "text/plain";
TIdAttachment* LogFile = new
TIdAttachment(MailMessage->MessageParts, FileToAttach);
LogFile->FileName = ExtractFileName(FileToAttach);
//LogFile->ContentType = GetMIMETypeFromFile(LogFile->FileName);
LogFile->ContentType = "application/zip";
SMTPClient->Connect();
try
{
SMTPClient->Send(MailMessage);
}
__finally
{
SMTPClient->Disconnect();
}
Log->Lines->Add("TestFunction Completed");
return 0;
}
Gambit
Re: Attachment missing from email
Author: Royce
Date: Thu, 06 Sep 2007 21:23
Date: Thu, 06 Sep 2007 21:23
60 lines
2864 bytes
2864 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Royce Fessenden" <rfessenden@dmp.com> wrote in message
>news:46e03084$1@newsgroups.borland.com...
>
>> I can send an email but I can't get the attachment to be included.
>
>That is because you are putting the text in the wrong place and setting the
>wrong ContentType for the message. Try this instead:
>
> int TMainForm::TestFunction(void)
> {
> AnsiString FileToAttach = "C:\\Link\\Logs\\Logs.zip";
>
> if( !FileExists(FileToAttach) )
> {
> Log->Lines->Add("File <" + FileToAttach + "> does not exist.");
> return -1;
> }
>
> Log->Lines->Add("Attaching file " + FileToAttach);
> TDMPCursor MyCursor(crHourGlass);
>
> MailMessage->ContentType = "multipart/mixed";
>
> TIdText *txt = new TIdText(MailMessage->MessageParts, NULL);
> txt->Body->Add("With attachment.");
> txt->ContentType = "text/plain";
>
> TIdAttachment* LogFile = new
>TIdAttachment(MailMessage->MessageParts, FileToAttach);
> LogFile->FileName = ExtractFileName(FileToAttach);
> //LogFile->ContentType = GetMIMETypeFromFile(LogFile->FileName);
> LogFile->ContentType = "application/zip";
>
> SMTPClient->Connect();
> try
> {
> SMTPClient->Send(MailMessage);
> }
> __finally
> {
> SMTPClient->Disconnect();
> }
>
> Log->Lines->Add("TestFunction Completed");
> return 0;
> }
>
>
>Gambit
>
>
Now I'm getting an Access violation at the line: txt->Body->Add("With attachment.");
Body appears to be NULL, though the debug shows a valid address for the ->Add() method. I tried several things, including replacing the NULL (second parameter) in the txt constructor with MailMessage->Body. I can change the place where I get an error, but anything that will run and send an email does not send the attachment. There's got to be something else I'm missing.
Royce
Re: Attachment missing from email
Author: Remy Lebeau (TeamB)
Date: Thu, 06 Sep 2007 21:30
Date: Thu, 06 Sep 2007 21:30
17 lines
1291 bytes
1291 bytes
"Royce" <rfessenden@dmp.com> wrote in message
news:46e06fc0$1@newsgroups.borland.com...
> Now I'm getting an Access violation at the line:
> txt->Body->Add("With attachment.");
>
> Body appears to be NULL
It cannot be. TIdText's constructor instantiates it.
> though the debug shows a valid address for the ->Add() method.
That doesn't mean anything.
Gambit
Re: Attachment missing from email
Author: Royce
Date: Fri, 07 Sep 2007 18:45
Date: Fri, 07 Sep 2007 18:45
25 lines
1737 bytes
1737 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Royce" <rfessenden@dmp.com> wrote in message
>news:46e06fc0$1@newsgroups.borland.com...
>
>> Now I'm getting an Access violation at the line:
>> txt->Body->Add("With attachment.");
>>
>> Body appears to be NULL
>
>It cannot be. TIdText's constructor instantiates it.
>
>> though the debug shows a valid address for the ->Add() method.
>
>That doesn't mean anything.
>
>
>Gambit
>
>
I didn't think it would be of much use, but then I'm not a Builder or C++ guru by any means. At any rate, the original code compiled and ran, but did not give the desired result. The modified code fails at run time, and anything I try that does not give the runtime error gives the same result as the original code.
Is there any other information I might be able to provide that might help?
Re: Attachment missing from email
Author: Remy Lebeau (TeamB)
Date: Fri, 07 Sep 2007 19:21
Date: Fri, 07 Sep 2007 19:21
10 lines
1311 bytes
1311 bytes
"Royce" <rfessenden@dmp.com> wrote in message news:46e19c52$1@newsgroups.borland.com... > Is there any other information I might be able to provide that might help? Please show the exact code you are using now. Gambit
Re: Attachment missing from email
Author: Royce
Date: Fri, 07 Sep 2007 21:39
Date: Fri, 07 Sep 2007 21:39
86 lines
3270 bytes
3270 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"Royce" <rfessenden@dmp.com> wrote in message
>news:46e19c52$1@newsgroups.borland.com...
>
>> Is there any other information I might be able to provide that might help?
>
>Please show the exact code you are using now.
>
>
>Gambit
>
>
>
int TMainForm::TestFunction(void)
{
AnsiString FileToAttach = "C:\\Link\\Logs\\Logs.zip";
if( !FileExists(FileToAttach) )
{
Log->Lines->Add("File <" + FileToAttach + "> does not exist.");
return -1;
}
Log->Lines->Add("Attaching file " + FileToAttach);
TDMPCursor MyCursor(crHourGlass);
MailMessage->ContentType = "multipart/mixed";
TIdText* txt = new TIdText(MailMessage->MessageParts, NULL);
txt->ContentType = "text/plain";
txt->Body->Append("txt With zips attached.");
TIdAttachment* LogFile = new TIdAttachment(MailMessage->MessageParts, FileToAttach);
LogFile->FileName = ExtractFileName(FileToAttach);
//LogFile->ContentType = GetMIMETypeFromFile(LogFile->FileName);
LogFile->ContentType = "application/zip";
SMTPClient->Connect();
try
{
SMTPClient->Send(MailMessage);
}
__finally
{
SMTPClient->Disconnect();
}
Log->Lines->Add("TestFunction Completed");
return 0;
}
The .dfm settings of the components are as follows:
object SMTPClient: TIdSMTP
MaxLineAction = maException
Host = 'mail.dmp.com'
Port = 25
AuthenticationType = atNone
HeloName = 'Link'
Password = 'xxxxxx'
Username = 'engtesting'
Left = 176
Top = 52
end
object MailMessage: TIdMessage
AttachmentEncoding = 'MIME'
BccList = <>
CCList = <>
ContentType = 'Application/Zip'
ContentTransferEncoding = 'Base64'
Encoding = meMIME
From.Address = 'engtesting@dmp.com'
From.Name = 'engtesting'
From.Text = 'engtesting <engtesting@dmp.com>'
Recipients = <
item
Address = 'rfessenden@dmp.com'
Name = 'Royce'
Text = 'Royce <rfessenden@dmp.com>'
end>
ReplyTo = <>
Subject = 'Email via Link'
Left = 176
Top = 104
end
Re: Attachment missing from email
Author: Remy Lebeau (TeamB)
Date: Fri, 07 Sep 2007 22:03
Date: Fri, 07 Sep 2007 22:03
11 lines
1315 bytes
1315 bytes
"Royce" <rfessenden@dmp.com> wrote in message news:46e1c522$1@newsgroups.borland.com... > int TMainForm::TestFunction(void) How are you setting up the TIdMessage prior to calling TestFunction()? Are you ever clearing the TIdMessage between sendings? Gambit
Re: Attachment missing from email
Author: Royce
Date: Mon, 10 Sep 2007 14:27
Date: Mon, 10 Sep 2007 14:27
22 lines
1624 bytes
1624 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Royce" <rfessenden@dmp.com> wrote in message >news:46e1c522$1@newsgroups.borland.com... > >> int TMainForm::TestFunction(void) > >How are you setting up the TIdMessage prior to calling TestFunction()? Are >you ever clearing the TIdMessage between sendings? > > >Gambit > > The only "setup" is setting properties directly on the form. (Sender, Receipients, etc.) I am not calling clear. The application is a shell with an <Execute> button used for testing code snippets. All applicable code is in TestFunction(). Royce
Re: Attachment missing from email
Author: Remy Lebeau (TeamB)
Date: Mon, 10 Sep 2007 17:58
Date: Mon, 10 Sep 2007 17:58
13 lines
1654 bytes
1654 bytes
"Royce" <rfessenden@dmp.com> wrote in message news:46e55443$1@newsgroups.borland.com... > The only "setup" is setting properties directly on the form. (Sender, Receipients, etc.) I am not calling clear. You need to clear the TIdMessage between sendings. Otherwise, the data from a previous message will carry over into the next message (if you are sending multiple messages to begin with, that is). Gambit
Re: Attachment missing from email
Author: Royce
Date: Tue, 18 Sep 2007 12:50
Date: Tue, 18 Sep 2007 12:50
21 lines
1950 bytes
1950 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Royce" <rfessenden@dmp.com> wrote in message >news:46e55443$1@newsgroups.borland.com... > >> The only "setup" is setting properties directly on the form. (Sender, >Receipients, etc.) I am not calling clear. > >You need to clear the TIdMessage between sendings. Otherwise, the data from >a previous message will carry over into the next message (if you are sending >multiple messages to begin with, that is). > > >Gambit > > I finally figured it out. I had to add winsock2.hpp to the files to be included. And I had to reorder the directory list so that the Indy we were using was used before the Indy that ships with Borland. (I had added _WINSOCKAPI_ to the defines but that did not solve the issues.) Royce
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads