Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple email question

Status
Not open for further replies.

delfy

MIS
Feb 8, 2005
96
JM
i send email using delphi with code below which works fine. The problem is this the email account (username) that i use to send the email when i log into that account i don't see the email i sent through delphi in my sent message folder. How can i ensure that all message sent out are saved in the sent items folder here is the code below
(username is a virtual email account having Maildir format)



// Setup SMTP
SMTP.Host := edHost.Text;
SMTP.Port := 25;
SMTP.AuthenticationType := atLogin;
SMTP.UserId := 'username';
SMTP.Password := 'username';


//Setup Mail Message
MailMessage.From.Address := edFrom.Text;

//Recipients
MailMessage.Recipients.EMailAddresses := edTO.Text;
MailMessage.CCList.EMailAddresses := edCC.Text;
MailMessage.BccList.EMailAddresses := edBcc.Text;

//Message
MailMessage.Subject := edSubject.Text;
MailMessage.Body.Text := meMessage.Text;


if FileExists(edAttachment.Text) then
TIdAttachment.Create(MailMessage.MessageParts, edAttachment.Text);


//Finally Send Email
try
try

SMTP.Connect();
SMTP.Send(MailMessage);
edAttachment.Clear;
showmessage('Message Sent');
except on E:Exception do
meStatus.Lines.Insert(0, 'ERROR: ' + E.Message);

end;
finally
if SMTP.Connected then
SMTP.Disconnect;

end;

 
You're not seeing it in Sent Items because you're accessing the mail server directly through an SMTP connnection instead of going through Outlook (or whatever email program you use) to send the mail.

One option (the easiest) would be to send the email to BOTH the requested recipient and the sender. It won't show up in the Sent Items folder, but the sender could move it there when it appears in the Inbox.

Another option would be to connect to Outlook through OLE and send the email from there instead of using a direct SMTP connection.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
ok i tried it using outlook and yes the message is stored in the sent items of the local folder not the sent items of the imap folder? using outlook 2003

try
Outlook := GetActiveOleObject('Outlook.Application');
except
outlook := CreateOleObject('Outlook.Application');
end;

MailItem := Outlook.CreateItem(olMailitem);
MailItem.Recipients.Add ('user@mydomain.com');
MailItem.Subject := 'Certs';
MailItem.Body := 'visit my webpage';
MailItem.Attachments.Add('C:\test.doc');
MailItem.Send;


Outlook := Unassigned;
 
oh i also have another problem this line Outlook := GetActiveOleObject('Outlook.Application'); causes and exception if the outlook is not already opened and the program stops at that line even though i have in it a try block why?

 
Does it stop when you run it in Delphi, and is it Ok if you run it stand alone?
You can change the way exceptions are handled by the Delphi debugger, this might be in a different menu depends on your version of Delphi.





Steve
Time for a new sig a bit of DNA I think will scan books and get back to you.
 
Yes it stops and when i run outlook standalone it works fine. I am using Version 6 of delphi
 
The problem is that you're calling "GetActiveOleObject" which, according to the Delphi Help file, "Retrieves a reference to an IDispatch interface to a currently running, registered COM object" (underline is mine). You need to use "CreateOleObject" instead if there is a possibility that Outlook is not already open.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top