Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Charles W Leggette
Fri, 30 Jul 2004 01:02
I need a simple example of sending an email
Author: Charles W Leggette
Date: Fri, 30 Jul 2004 01:02
Date: Fri, 30 Jul 2004 01:02
3 lines
1061 bytes
1061 bytes
Why is this so daggone hard. Please use code that can run under C++bldr 6, sp4. Its easy as pie under MS VC++6.0 or 7.0??? I've tried FastNet,etc...no success.
Re: I need a simple example of sending an email
Author: Eugene Mayevski [SecureBlackbox]
Date: Fri, 30 Jul 2004 10:39
Date: Fri, 30 Jul 2004 10:39
18 lines
1714 bytes
1714 bytes
Charles W Leggette wrote: > Why is this so daggone hard. Please use code that can run under C++bldr 6, > sp4. Its easy as pie under MS VC++6.0 or 7.0??? Pure curiosity -- *why* this is easy with VC++, i.e. what exactly (some class, code snippet, tutorial or smth. else) makes it easy? Maybe you just need the adequate thing for BCB? Regarding your question -- check Indy or ICS components or Synapse class. FastNet is outdated, unsupported and buggy. -- Eugene Mayevski EldoS Corp., CTO Networking and security solutions, development and consulting services http://www.eldos.com
Re: I need a simple example of sending an email
Author: Colin B Maharaj
Date: Wed, 04 Aug 2004 11:14
Date: Wed, 04 Aug 2004 11:14
160 lines
4597 bytes
4597 bytes
Charles W Leggette wrote:
> Why is this so daggone hard. Please use code that can run under C++bldr 6,
> sp4. Its easy as pie under MS VC++6.0 or 7.0??? I've tried FastNet,etc...no
> success.
>
>
This is straight from an application I am writing... no time to clean it
up need to go to work.........
AnsiString SendMail(AnsiString emailto, AnsiString subject, AnsiString
MailFile)
{
TWinshoeSMTP * SMTP;
TWinshoeMessage * msg;
AnsiString Attachment;
AnsiString SendMsg = "Mail Sent OK";
bool Attached = false;
int state=0;
SMTP = new TWinshoeSMTP(NULL);
msg = new TWinshoeMessage(NULL);
try
{
SMTP->Host = Host2;// External Var e.g. mail.whocares.com
SMTP->UserID = UserID2;// External Var e.g. jd
msg->Subject = subject;
AnsiString From = (AnsiString)"John Doe <jd@whocares.com">";
msg->From = From;
AnsiString EM = "~";
int q=0;
while (EM != " ")
{
EM = GetCsvParameter(emailto.c_str(), q++);
if (EM.Length()>1)
{
if (q == 1)
{
msg->Too->Text = EM;
}
else
{
msg->CCList->Add(EM);
}
}
}
AnsiString MailMsg = "See ZIPPED attachment for report";
// bool IsRtf = false;
if (MailFile.Pos(".rtf") > 0) msg->ContentType = "application/rtf";
if (MailFile.Pos(".htm") > 0) msg->ContentType = "text/html";
if (MailFile.Pos(".doc") > 0) msg->ContentType = "text/plain";
if (FileExists(MailFile)==false)
{
MailMsg = MailFile + " not found, or no data in report!";
}
else
{
if (GetFileSize(MailFile.c_str()) > (10*1024))
{
// Attachment = DoZipFile(MailFile.c_str(), MailFile.c_str());
msg->Attachments->AddAttachment(Attachment);
Attached = true;
}
else
{
TStringList * S = new TStringList;
S->LoadFromFile(MailFile);
msg->Text = S;
S->Clear();
delete S;
}
}
state = 1;
SMTP->Send(msg);
delete msg;
delete SMTP;
state = 0;
// if (Attached == true) DeleteFile(Attachment);
}
catch (Exception & e)
{
SendMsg = (AnsiString) "Email Error : " + e.Message;
if (state==1)
{
SMTP->Disconnect();
}
delete SMTP;
delete msg;
if (Attached ==true) DeleteFile(Attachment);
return SendMsg;
}
catch (...)
{
delete SMTP;
delete msg;
SendMsg = "Email Error : Undefined error";
return SendMsg;
}
return SendMsg;
}
// used to separate comma separated email addresses..
AnsiString GetCsvParameter(const char *s, int index)
{
AnsiString ret = (AnsiString) " ";
int numcommas=0;
int len = strlen(s);
for (int i=0; i<len; i++)
{
if (s[i]=='\,') numcommas++;
}
if (numcommas == 0 && index == 0)
{
ret = s; return ret;
}
if (numcommas < index)
{
return ret;
}
int n = index;
while (n && *s)
{
if (*s++ == '\,')
{
n--;
}
}
if (!*s) return ret;
char *t = new char [1024]; // NOT an Error. Other pointer deleted.
int q = 0;
while (*s && *s=='\,') s++; /// was while could cause errors if ,,
while (*s && *s!='\,' && q < 1023)
{
t[q++] = *s++;
}
t[q++] = NULL;
ret = t;
delete t;
return ret;
}
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