Einzelnen Beitrag anzeigen

Ralf Meyer

Registriert seit: 24. Mär 2008
36 Beiträge
 
#7

Re: E-Mail mit Anhang im E-Mailclient

  Alt 24. Dez 2009, 23:13
Hi,

hier mein Code zum versenden:
Delphi-Quellcode:
function SendFileMail(const FileName: TFileName; const Subject, BodyText, RecipAdress: String): String;
var
  mMessage: TMapiMessage;
  mlpFiles: TMapiFileDesc;
  mRecips: TMapiRecipDesc;
begin
  if not FileExists(FileName) then
  begin
    Result := 'File "' + FileName + '" not found!';
    Exit;
  end;

  with mRecips do
  begin
    ulRecipClass := MAPI_TO;
    lpszName := PChar(RecipAdress);
    lpszAddress := PChar(RecipAdress);
    ulEIDSize := 0;
    lpEntryID := nil;
  end;

  with mlpFiles do
  begin
    flFlags := 0;
    nPosition := 0;
    lpszPathName := PChar(FileName);
    lpszFileName := nil;
    lpFileType := nil;
  end;

  with mMessage do
  begin
    lpszSubject := PChar(Subject);
    lpszNoteText := PChar(BodyText);
    lpszMessageType := nil;
    lpszDateReceived := nil;
    lpszConversationID := nil;
    flFlags := 0;
    lpOriginator := nil;
    nRecipCount := 1;
    lpRecips := @mRecips;
    nFileCount := 0;
    lpFiles := @mlpFiles;
  end;

  case MapiSendMail(0, 0, mMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0) of
    MAPI_E_AMBIGUOUS_RECIPIENT:
      Result := 'A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set!';
    MAPI_E_ATTACHMENT_NOT_FOUND:
      Result := 'The specified attachment was not found!';
    MAPI_E_ATTACHMENT_OPEN_FAILURE:
      Result := 'The specified attachment could not be open!';
    MAPI_E_BAD_RECIPTYPE:
      Result := 'The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC!';
    MAPI_E_FAILURE:
      Result := 'One or more unspecified errors occurred!';
    MAPI_E_INSUFFICIENT_MEMORY:
      Result := 'There was insufficient memory to proceed!';
    MAPI_E_LOGIN_FAILURE:
      Result := 'There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed!';
    MAPI_E_TEXT_TOO_LARGE:
      Result := 'The text in the message was too large to sent!';
    MAPI_E_TOO_MANY_FILES:
      Result := 'There were too many file attachments!';
    MAPI_E_TOO_MANY_RECIPIENTS:
      Result := 'There were too many recipients!';
    MAPI_E_UNKNOWN_RECIPIENT:
      Result := 'A recipient did not appear in the address list!';
    MAPI_E_USER_ABORT:
      Result := 'The user canceled one of the dialog boxes!';
  end;
end;

Function Mail1( Const cTo, cSubject, cMessage : String ) : Boolean ;
var
  S: String;
Begin
  S := SendFileMail( 'C:\test.txt', cSubject, cMessage, cTo ) ;

  if Length(S) > 0 then
  begin
    MessageDlg('Die Datei konnte nicht per E-Mail versendet werden!' + #10#13#10#13 +
      'Meldung:' + #10#13 + S, mtError, [mbOK], 0);
  end;

end;
Den Fehler von devidespe bekomme ich mit diesem Code nicht. Das Versenden klappt einwandfrei.

Ich habe jedoch ein anderes Problem.
Der E-Mail Typ wird auf auf die Ziel E-Mail-Adresse gesetzt und nicht auf SMTP wie es sein müßte. Somit kommt keine Mail an.

Gruß
Ralf
  Mit Zitat antworten Zitat