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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

urgent help with MAPI

Status
Not open for further replies.

delphi6BDE

Programmer
Sep 28, 2009
21
CA
I have made a program that will enter information into a database and send out an email to a specific user. The user that gets the email must resolve the problem and reply back to a group, not the individual who sent it. This is a necessary step in case the original person who sent the email is out of office. These emails must be resolved in a timely manner, which is why I want it going bak to a group, instead of the original sender. Below is the code that I found on Google which is working great, except for the 'Reply-To'. I've tried setting lpSender to the email address I want the users to reply to, but it instead always shows the senders email. How do I get around this?

code to send:

Code:
function SendMail(const Subject, Body, FileName, SenderName, SenderEmail, RecipientName, RecipientEmail: string): Integer;
var
	Message: TMapiMessage;
	lpSender, lpRecipient: TMapiRecipDesc;
	FileAttach: TMapiFileDesc;
	SM: TFNMapiSendMail;
	MAPIModule: HModule;
begin
	FillChar(Message, SizeOf(Message),0);
	with Message do
		begin
			if(Subject <> '') then
				lpszSubject := PChar(Subject);

			if(Body <> '') then
				lpszNoteText := PChar(Body);

         	        if(SenderEmail <> '') then
				begin
					lpSender.ulRecipClass := MAPI_ORIG;
					if (SenderName = '') then
						lpSender.lpszName := PChar(SenderEmail)
					else
						lpSender.lpszName := PChar(SenderName);
					lpSender.lpszAddress := PChar('SMTP:'+SenderEmail);
					lpSender.ulReserved:= 0;
					lpSender.ulEIDSize :=0;
					lpSender.lpEntryID := nil;
					lpOriginator := @lpSender;
				end;

         		if (RecipientEmail <> '') then
				begin
					lpRecipient.ulRecipClass := MAPI_TO;
					if (RecipientName = '') then
						lpRecipient.lpszName := PChar(RecipientEmail)
					else
						lpRecipient.lpszName := PChar(RecipientName);
					lpRecipient.lpszAddress := PChar('SMTP:'+RecipientEmail);
					lpRecipient.ulReserved:= 0;
					lpRecipient.ulEIDSize := 0;
					lpRecipient.lpEntryID := nil;
					nRecipCount := 1;
					lpRecips := @lpRecipient;
				end
			else
				lpRecips := nil;

			if (FileName = '') then
				begin
					nFileCount := 0;
					lpFiles := nil;
				end
			else
				begin
					FillChar(FileAttach, SizeOf(FileAttach), 0);
					FileAttach.nPosition := Cardinal($FFFFFFFF);
					FileAttach.lpszPathName := PChar(FileName);

					nFileCount := 1;
					lpFiles := @FileAttach;
				end;
		end;

		MAPIModule := LoadLibrary(PChar(MAPIDLL));
		if MAPIModule = 0 then
			Result := -1
		else
			try
				@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
				if @SM <> nil then
					begin
						Result := SM(0, Application.Handle, Message, MAPI_DIALOG or MAPI_LOGON_UI, 0);
					end
				else
					Result := 1;
			finally
				FreeLibrary(MAPIModule);
			end;

		if Result <> 0 then
			MessageDlg('Error sending email(' + IntToStr(Result) +').', mtError, [mbOK], 0);
end;
 
I'm not familiar with TMapiMessage - I do all my e-mailing with the Indy components TIdMessage and TidSMTP.

In terms of terminology though, From and Sender both relate to where the e-mail appears to be coming from. ReplyTo is the property you want to use that can be different to both From and Sender, and is what an e-mail client should display when the user clicks Reply.
 
Agreed. So does anybody know how to add a reply-to to that code? I've googled it and find nothing. Maybe my keywords are wrong though
 
From microsoft's description of MapiMessage, it would seem that this property is not available in this class.

Indy's TIdMessage has this property. I would recommend, if possible, changing to use it instead.
 
Would that work in an exchange environment?

I have different code working by calling outlook, but I get that stupid security warning every time an email goes out, so I decided to try mapi
 
TIdSMTP will work with exchange (just set the Host to the exchange server IP), but your message won't appear in the Sent Items in any mailbox. You may need to enable relaying on the exchange server for the PC running your app for this to work properly.

Indy also has a TIdIMAP4 object - this may do what you want, but I've never used it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top