-
Notifications
You must be signed in to change notification settings - Fork 9
/
BuildQueryParameters.pas
58 lines (46 loc) · 1.72 KB
/
BuildQueryParameters.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
unit BuildQueryParameters;
interface
uses
AmazonEmailMessage,
AmazonEmailService,
System.Classes;
type
TBuildQueryParameters = class
public
class function GetQueryParams(const EmailMessage: TEmailMessage): TStringStream;
end;
implementation
uses
SysUtils,
EncodeQueryParams,
System.NetEncoding;
class function TBuildQueryParameters.GetQueryParams(const EmailMessage: TEmailMessage): TStringStream;
const
Action = 'SendEmail';
var
I: Integer;
BodyType, Source: string;
begin
Result := TStringStream.Create(EmptyStr, TEncoding.UTF8);
try
Result.WriteString('Action=' + ACTION);
Source := Format('=?utf-8?B?%s?= <%s>', [TNetEncoding.Base64.Encode(EmailMessage.FromName), EmailMessage.FromAddress]);
Result.WriteString(Format('&Source=%s', [TEncodeQueryParams.Encode(Source)]));
for I := Low(EmailMessage.Recipients) to High(EmailMessage.Recipients) do
Result.WriteString(Format('&Destination.ToAddresses.member.%d=%s', [I+1, TEncodeQueryParams.Encode(EmailMessage.Recipients[I])]));
for I := Low(EmailMessage.ReplyTo) to High(EmailMessage.ReplyTo) do
Result.WriteString(Format('&ReplyToAddresses.member.%d=%s', [I+1, TEncodeQueryParams.Encode(EmailMessage.ReplyTo[I])]));
Result.WriteString('&Message.Subject.Charset=UTF-8');
Result.WriteString(Format('&Message.Subject.Data=%s', [TEncodeQueryParams.Encode(EmailMessage.Subject)]));
if EmailMessage.BodyType = btHTML then
BodyType := 'Html'
else
BodyType := 'Text';
Result.WriteString(Format('&Message.Body.%s.Charset=UTF-8', [BodyType]));
Result.WriteString(Format('&Message.Body.%s.Data=%s', [BodyType, TEncodeQueryParams.Encode(EmailMessage.Body)]));
except
Result.Free;
raise
end;
end;
end.