📄 unit_mysendmailbyhtml.pas
字号:
unit Unit_MySendMailByHtml;
{
const
MailAspUrl:string='http://www.138soft.com/Singularity/BugReport.asp?Tomail=lovejingtao@21cn.com&MailBody=';
var
StrMailBody:string;
begin
StrMailBody:=HtmlEncode(Application.Title+#13+Trim('信件内容')+#13+'发信人Email:'+Trim('lovejingtao@21cn.com')+#13);
if SendHtmlMail(MailAspUrl+StrMailBody) then Application.MessageBox('发送BUG报告成功!',Pchar(Application.Title),MB_ICONINFORMATION)
else Application.MessageBox('发送BUG报告失败!',Pchar(Application.Title),MB_ICONINFORMATION);
end;
}
interface
uses
Windows,MySocket,MySysUtils,MyReg;
function HtmlEncode(s: string): string;stdcall;
function SendHtmlMail(html: string):Boolean;stdcall;
implementation
const
SOCKET_ERROR = -1;
function IsUseHttpProxy(var ProxyIp:String;var ProxyPort:integer):Boolean;
var
Str:String;
iPos:integer;
begin
Result:=False;
if not ValueExists(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyEnable') then Exit;
if ReadIntegerValue(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyEnable')<>1 then Exit;
if not ValueExists(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyServer') then Exit;
Str:=ReadStringValue(HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Internet Settings','ProxyServer');
if Str='' then Exit;
iPos:=Pos(':',Str);
if iPos<=0 then Exit;
ProxyIp:=Copy(Str,1,iPos-1);
Delete(Str,1,iPos);
Val(str,ProxyPort,iPos);
if iPos<>0 then Exit;
Result:=True;
end;
function HtmlEncode(s: string): string;stdcall;
var
i, v1, v2: integer;
function i2s(b: byte): char;
begin
if b <= 9 then result := chr($30 + b)
else result := chr($41 - 10 + b);
end;
begin
result := '';
for i := 1 to length(s) do
if s[i] = ' ' then result := result + '+'
else if (s[i] < ' ') or (s[i] in ['/', '\', ':', '&', '?', '|']) then
begin
v1 := ord(s[i]) mod 16;
v2 := ord(s[i]) div 16;
result := result + '%' + i2s(v2) + i2s(v1);
end
else result := result + s[i];
end;
function SendHtmlMail(html: string):Boolean;stdcall;
var
host, hoststring: string;
port: integer;
i: integer;
E: Integer;
FSock: integer;
//------------------
ProxyIp:String;
ProxyPort:integer;
SendStr:string;
StrIP:string;
begin
Result:=False;
if uppercase(copy(html, 1, 7)) <> 'HTTP://' then exit;
hoststring := copy(html, 8, maxint);
i := pos('/', hoststring);
if i <> 0 then
delete(hoststring, i, maxint);
i := pos(':', hoststring);
if i = 0 then
begin
host := hoststring;
port := 80;
end
else begin
host := copy(hoststring, 1, i - 1);
Val(copy(hoststring, i + 1, maxint), port, E);
if E <> 0 then port := 80;
end;
//------------使用了代理服务器Start---------------
if IsUseHttpProxy(ProxyIp,ProxyPort) then
begin
if not StartNet(ProxyIp,ProxyPort,Fsock) then
begin
StopNet(Fsock);
Exit;
end;
//SendStr:=Format('CONNECT %s:%d HTTP/1.0'#$d#$a#$d#$a + 'Host %s'#$d#$a, [RemoteTcpIp, RemoteTcpPort, RemoteTcpIp]);
SendStr:='CONNECT '+Host+':80 HTTP/1.0'#$d#$a#$d#$a + 'Host '+Host+#$d#$a;
SendData(Fsock,SendStr);
SendStr:=GetData(Fsock);
Result:=Pos('HTTP/1.0 200',SendStr)>0;
StopNet(Fsock);
Exit;
end
//------------使用了代理服务器Stop---------------
else
begin
StrIP:=GetIpbyHost(Host);
if StrIP='' then
begin
StopNet(Fsock);
Exit;
end;
if not StartNet(StrIP,80,Fsock) then
begin
StopNet(Fsock);
Exit;
end;
// if StartNet(getip(host), port, FSocket) then
// begin
if SendData(FSock,
'GET ' + html + ' HTTP/1.0'#$D#$A +
'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*'#$D#$A +
'Accept-Language: zh-cn'#$D#$A +
'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'#$D#$A +
'Host: ' + Hoststring + #$D#$A +
'Proxy-Connection: Keep-Alive'#$D#$A#$D#$A)=SOCKET_ERROR then { SOCKET_ERROR = -1;}
begin
StopNet(Fsock);
Exit;
end;
Result:=Pos('发送成功!',getdata(FSock))>0;
StopNet(Fsock);
// end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -