Board index » delphi » EMail with Outlook

EMail with Outlook


2007-02-26 04:05:19 PM
delphi72
Hi everybody
I try to send EMails from my Delphi 7 application, using outlook. I found
some code (see below) but with this I have 2 problems:
- If i send this EMail outlook puts a message in the inbox saying that no of
my email-accounts is able to send this message. If I delete the
receipent-address and rewrite it manually it works.
- Second problem: I should add the standard-signature to this emails but
with this method I don't get the signature.
Thanks for your help. Maybe I have to use another solution.
Peter
My code:
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMailWithOutlook('Test','This is a
test','Peter','XXXX@XXXXX.COM','XXXX@XXXXX.COM','','',nil,true);
end;
function SendMailWithOutlook(Subject,Mailtext,
FromName,FromAdress,
ToAdress, ToCC, ToBCC: string;
AttachedFileNames : TStrings;
ShowDialog:boolean) : boolean;
var
MapiMessage : TMapiMessage;
MError : Cardinal;
Empfaenger : Array[0..2] of TMapiRecipDesc;
Absender : TMapiRecipDesc;
Datei : Array[0..100] of TMapiFileDesc;
i : integer;
begin
with MapiMessage do begin
ulReserved := 0;
// Betreff
lpszSubject := PChar(Subject);
// Body
lpszNoteText := PChar(Mailtext);
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
// Absender festlegen
Absender.ulReserved:=0;
Absender.ulRecipClass:=MAPI_ORIG;
Absender.lpszName:= PChar(FromName);
Absender.lpszAddress:= PChar(FromAdress);
Absender.ulEIDSize:=0;
Absender.lpEntryID:=nil;
lpOriginator := @Absender;
// Empfänger festlegen (Hier: nur 1 Empfänger)
nRecipCount := 0;
if ToAdress <>'' then
begin
Empfaenger[nRecipCount].ulReserved:=0;
Empfaenger[nRecipCount].ulRecipClass:=MAPI_TO;
Empfaenger[nRecipCount].lpszAddress:= PChar(ToAdress);
Empfaenger[nRecipCount].lpszName:=
Empfaenger[nRecipCount].lpszAddress;
Empfaenger[nRecipCount].ulEIDSize:=0;
Empfaenger[nRecipCount].lpEntryID:=nil;
Inc(nRecipCount);
end;
if ToCC <>'' then
begin
Empfaenger[nRecipCount].ulReserved:=0;
Empfaenger[nRecipCount].ulRecipClass:=MAPI_CC;
Empfaenger[nRecipCount].lpszAddress:= PChar(ToCC);
Empfaenger[nRecipCount].lpszName:=
Empfaenger[nRecipCount].lpszAddress;
Empfaenger[nRecipCount].ulEIDSize:=0;
Empfaenger[nRecipCount].lpEntryID:=nil;
Inc(nRecipCount);
end;
if ToBCC <>'' then
begin
Empfaenger[nRecipCount].ulReserved:=0;
Empfaenger[nRecipCount].ulRecipClass:=MAPI_BCC;
Empfaenger[nRecipCount].lpszAddress:= PChar(ToBCC);
Empfaenger[nRecipCount].lpszName:=
Empfaenger[nRecipCount].lpszAddress;
Empfaenger[nRecipCount].ulEIDSize:=0;
Empfaenger[nRecipCount].lpEntryID:=nil;
Inc(nRecipCount);
end;
lpRecips := @Empfaenger;
// Dateien anhängen (Hier: nur 1 Datei)
if AttachedFileNames <>nil then
begin
nFileCount := AttachedFileNames.Count;
// Name der Datei auf der Festplatte
for i := 0 to AttachedFileNames.Count-1 do
begin
Datei[i].lpszPathName:= PChar(AttachedFilenames[i]);
// Name, der in der Email angezeigt wird
Datei[i].lpszFileName:= pChar(AttachedFileNames[i]);
Datei[i].ulReserved:=0;
Datei[i].flFlags:=0;
Datei[i].nPosition:=Cardinal(-1);
Datei[i].lpFileType:=nil;
end;
end
else nFileCount := 0;
lpFiles := @Datei;
end;
// Senden
if ShowDialog then
MError := MapiSendMail(0, Application.Handle,
MapiMessage, MAPI_NEW_SESSION or MAPI_DIALOG or MAPI_LOGON_UI or
MAPI_USE_DEFAULT, 0)
else
// Wenn kein Dialogfeld angezeigt werden soll:
MError := MapiSendMail(0, Application.Handle, MapiMessage, 0, 0);
Case MError of
MAPI_E_AMBIGUOUS_RECIPIENT:
MessageDlg('Empfänger nicht eindeutig. (Nur möglich, wenn Emailadresse
nicht angegeben.)',mterror,[mbok],0);
MAPI_E_ATTACHMENT_NOT_FOUND:
MessageDlg('Datei zum Anhängen nicht gefunden',mterror,[mbok],0);
MAPI_E_ATTACHMENT_OPEN_FAILURE:
MessageDlg('Datei zum Anhängen konnte nicht geöffnet
werden.',mterror,[mbok],0);
MAPI_E_BAD_RECIPTYPE:
MessageDlg('Empfängertyp nicht MAPI_TO, MAPI_CC oder
MAPI_BCC.',mterror,[mbok],0);
MAPI_E_FAILURE:
MessageDlg('Unbekannter Fehler.',mterror,[mbok],0);
MAPI_E_INSUFFICIENT_MEMORY:
MessageDlg('Nicht genug Speicher.',mterror,[mbok],0);
MAPI_E_LOGIN_FAILURE:
MessageDlg('Benutzerlogin (z.B. bei Outlook)
fehlgeschlagen.',mterror,[mbok],0);
MAPI_E_TEXT_TOO_LARGE:
MessageDlg('Text zu gro?',mterror,[mbok],0);
MAPI_E_TOO_MANY_FILES:
MessageDlg('Zu viele Dateien zum Anhängen.',mterror,[mbok],0);
MAPI_E_TOO_MANY_RECIPIENTS:
MessageDlg('Zu viele Empfänger angegeben.',mterror,[mbok],0);
MAPI_E_UNKNOWN_RECIPIENT: MessageDlg('Empfänger nicht in Adressbuch
gefunden. '+
'(Nur möglich, wenn Emailadresse nicht angegeben.)',mterror,[mbok],0);
MAPI_E_USER_ABORT:
MessageDlg('Benutzer hat Senden abgebrochen oder MAPI nicht
installiert.',mterror,[mbok],0);
{ SUCCESS_SUCCESS:
MessageDlg('Erfolgreich !!! (Aber Absenden nicht
garantiert.)',mtinformation,[mbok],0);}
end;
Result := MError = SUCCESS_SUCCESS;
end;
 
 

Re:EMail with Outlook

Quote
- If i send this EMail outlook puts a message in the inbox saying that no
of
my email-accounts is able to send this message. If I delete the
receipent-address and rewrite it manually it works.
Add the smtp: prefix for recipient address (smtp:XXXX@XXXXX.COM instead
XXXX@XXXXX.COM)
 

Re:EMail with Outlook

Thanks a lot, it works great with "smtp"! Has somebody a solution for the
second problem with the "signatures"?
"Mike Shkolnik" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
>- If i send this EMail outlook puts a message in the inbox saying that no
of
>my email-accounts is able to send this message. If I delete the
>receipent-address and rewrite it manually it works.
Add the smtp: prefix for recipient address (smtp:XXXX@XXXXX.COM instead
XXXX@XXXXX.COM)

--
With best regards, Mike Shkolnik
Scalabium Software
www.scalabium.com
XXXX@XXXXX.COM



 

Re:EMail with Outlook

I found the solution: I have to add the signature as the first attachement.
Maybe "signature" is a wrong translation. What I mean is to add some text
(my address) and an image to the body.
Peter
"Peter Ruf" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
Thanks a lot, it works great with "smtp"! Has somebody a solution for the
second problem with the "signatures"?

"Mike Shkolnik" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
news:XXXX@XXXXX.COM...
>>- If i send this EMail outlook puts a message in the inbox saying that
>>no
>of
>>my email-accounts is able to send this message. If I delete the
>>receipent-address and rewrite it manually it works.
>Add the smtp: prefix for recipient address (smtp:XXXX@XXXXX.COM instead
>XXXX@XXXXX.COM)
>
>--
>With best regards, Mike Shkolnik
>Scalabium Software
>www.scalabium.com
>XXXX@XXXXX.COM
>
>
>