• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1980
  • Last Modified:

sending EMails with Delphi XE2 TMailItem

Hi everybody,

I developped an application with D7 that can send emails using outlook. Now I need to compile this application in Delphi XE2 but the object "TMailItem" is no longer defined (undeclared object). Which unit I have to import or what is the new way to do this job? Thanks for aour help, Peter
0
formi
Asked:
formi
  • 2
2 Solutions
 
ThommyCommented:
Use late binding for outlook automation...

Send an email (with attachment) from Outlook
http://delphi.about.com/cs/adptips2000/a/bltip0800_3.htm
0
 
formiAuthor Commented:
Thanks, thats a possible way. I found that I have to use the type MapiItem instead of TMaipItem.
0
 
formiAuthor Commented:
possible solution but not what I needed to know.
0
 
rinfoCommented:
Since XE TmailItem is replaced with mailitem.
However as reported in forums mailterm is not being recognized as object type and wokaround have been used successfully.
Var
Outlook: OleVariant;
vMailItem: variant;
mRecipient, mSubject, mBody, mAttachement : String;
begin

//Procedure SendEMail(mRecipient:String, mSubject:String, mBody:String, mAttachement:String);
try
Outlook := GetActiveOleObject('Outlook.Application');
except
Outlook := CreateOleObject('Outlook.Application');
end;
vMailItem := Outlook.CreateItem(olMailItem);
vMailItem.Recipients.Add(mRecipient);
vMailItem.Subject := mSubject;
vMailItem.Body := mBody;
vMailItem.Attachments.Add(mAttachement);
vMailItem.Send;

VarClear(Outlook);

end;

end.
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now