{************************************************ ******************************
This process is used to get the mail express delivery destination server name and priority number. The parameter AMXList is used to receive the result value. AQName represents the domain name passed over************************ *************************************************** **********}
procedure TQuickEMailFrm.GetMxList(AMxList: TStringList; AQName: string);
var
i: Integer;
begin
with IdDNSResolver do
begin
Host := 202.102.13.141 ; { The Host attribute is used to specify the address of the domain name server. This is the main domain name server address where the author is located. You can also specify any domain name server address on the Internet that can be quickly accessed. You must know where you are. The domain name server address can be found through the winipcfg command under win98 and through ipconfig /all under win2000. }
ReceiveTimeout := 10000; // If no feedback from the domain name server is obtained within the specified time, it is considered a failure.
ClearVars; // Clear the resource records returned by the previous query
{Construct the header structure of this query}
with DNSHeader do
begin
Qr := False; // False represents the query Opcode := 0; // 0 represents the standard domain name query RD := True; //The domain name server can perform recursive queries QDCount := 1; //The number of queries end;
{Construct the question to be queried}
DNSQDList.Clear;
with DNSQDList.Add do
begin
QName := AQName; //The domain name to be queried QType := cMX; //QTYPE specifies the type of resource record to be queried. The value cMX represents the mail exchange record QClass := cIN;
end;
ResolveDNS; //Send a request to the domain name server
{Receive the feedback result from the domain name server and put the feedback mail server name in the Name part of the AMXList list.
The priority number of the mail server is placed in the Value section. }
for i := 0 to DNSAnList.Count - 1 do
AMxList.Add(DNSAnList[i].RData.MX.Exchange + = +
IntToStr(DNSAnList[i].RData.MX.Preference));
end;
end;
{Send delivery email when "Send" button is clicked}
procedure TQuickEMailFrm.btnSendClick(Sender: TObject);
var
MxList: TStringList;
i: Integer;
QName, ThoughAddress: string;
begin
//Create an email based on the content filled in by the user with IdMsgSend do
begin
Body.Assign(mmContent.Lines); //Email text From.Address := Trim(edtFrom.Text); //Sender address Recipients.EMailAddresses := Trim(edtTo.Text); //Recipient address Subject := edtSubject.Text; //Email subject end;
//Get the email domain name from the entered recipient address, and use the previous GetMxList process to get the destination address QName := TrimRight(copy(edtTo.Text, Pos( @ , edtTo.Text) + 1, Length(edtTo.Text) )));
MxList := TStringList.Create;
try
GetMxList(MxList, QName);
ThoughAddress := MxList.Names[0];
{The first server with feedback is taken as the destination. Readers can make improvements according to actual needs, such as considering the priority of the mail or when the server you choose is temporarily unable to process your mail due to busyness, try using another server. try}
finally
MxList.Free;
end;
//Send email with IdSMTP do
begin
Host := ThoughAddress; // Assign Host as the destination. This is the difference between express mail and ordinary mail. Port := 25; // The default port of the smtp service is 25.
Connect; //Connect to the server try
Send(IdMsgSend); //Send the email just created ShowMessage(Sent completed); //Prompt finally after sending is completed
Disconnect; //Disconnect the server end;
end;
end;