我们使用Indy,需要在我们的应用程序中支持SSL电子邮件,但是我们需要将应用程序放在单个.Exe文件中。
我们知道默认的Indy处理程序需要在路径中拥有dll。从其中一个EXE资源中提取Dlls将是最后的选择。
还有更好的建议吗?
我们知道默认的Indy处理程序需要在路径中拥有dll。从其中一个EXE资源中提取Dlls将是最后的选择。
还有更好的建议吗?
“单个EXE”是用于分发目的还是在客户机上运行时也必须是单个.EXE文件?
如果仅用于分发目的,您可以将DLL文件附加到您的.EXE文件末尾,然后-当程序启动时-从.EXE文件中提取它们并将它们作为.DLL文件存储在本地,类似于这样:
VAR F,O : FILE;
VAR BUF : ARRAY[1..<MaxSizeOfDLLs>] OF BYTE;
ASSIGN(F,ParamStr(0)); RESET(F,1);
SEEK(F,<OriginalExeSize>);
BLOCKREAD(F,BUF,<FirstDllSize>);
ASSIGN(O,<NameOfFirstDLL>); REWRITE(O,1);
BLOCKWRITE(O,BUF,<FirstDllSize>); CLOSE(O);
BLOCKREAD(F,BUF,<SecondDllSize>);
ASSIGN(O,<NameOfSecondDLL>); REWRITE(O,1);
BLOCKWRITE(O,BUF,<SecondDllSize>); CLOSE(O);
SEEK(F,<OriginalExeSize>); TRUNCATE(F); CLOSE(F)
这只是一个快速而简单的程序,格式并不规范,但应该可以给你基本的概念。
IdSSLOpenSSLHeaders_static.pas
单元,用于静态链接到OpenSSL。它仅适用于iOS,但如果您有适合的OBJ,则可以将其调整为在其他平台上运行。 - Remy Lebeau我使用微软的CAPICOM来解决我的SSL3需求...它是免费可再分发的但已经停止更新了。
如果你尝试其他组件,也许你应该看看SYNAPSE(位于http://synapse.ararat.cz/)(我也在使用),它可以与StreamSec(和其他组件)一起工作,以通过SSL发送电子邮件。它是免费且易于使用。
常量
cdoSendUsingMethod = 'http://schemas.microsoft.com/cdo/configuration/sendusing';
cdoSMTPServer = 'http://schemas.microsoft.com/cdo/configuration/smtpserver';
cdoSMTPServerPort = 'http://schemas.microsoft.com/cdo/configuration/smtpserverport';
cdoSendServerPort = '25';
cdoSendUsingPort = 2;
cdoSMTPConnectionTimeout = 'http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout';
cdoSMTPAuthenticate = 'http://schemas.microsoft.com/cdo/configuration/smtpauthenticate';
cdoAnonymous = '0';
cdoBasic = '1';
cdoSMTPUseSSL = 'http://schemas.microsoft.com/cdo/configuration/smtpusessl';
cdoSendUserName = 'http://schemas.microsoft.com/cdo/configuration/sendusername';
cdoSendPassword = 'http://schemas.microsoft.com/cdo/configuration/sendpassword';
cdoURLGetLatestVersion = 'http://schemas.microsoft.com/cdo/configuration/urlgetlatestversion';
...
function SensCDOMail (ASubject, AFrom, ATo, ABody, ASmtpServer : WideString): String;
var
cdoMessage:OleVariant;
cdoConfiguration: OleVariant;
begin
//Configuration Object
cdoMessage:= CreateOleObject('CDO.Message');
cdoConfiguration:= CreateOleObject('CDO.Configuration');
try
cdoConfiguration.Fields(cdoSendUsingMethod):= cdoSendUsingPort;
cdoConfiguration.Fields(cdoSMTPServer):= ASmtpServer;
cdoConfiguration.Fields(cdoSMTPServerPort):= cdoSendServerPort;
cdoConfiguration.Fields(cdoSMTPAuthenticate):= cdoAnonymous;
cdoConfiguration.Fields(cdoSMTPUseSSL ):= True; // use SSL
cdoConfiguration.Fields.Update;
cdoMessage.Configuration:= cdoConfiguration;
cdoMessage.To := ATo;
cdoMessage.From := AFrom;
cdoMessage.Subject := ASubject;
//cdoMessage.HTMLBody := ABody; //Want to send in Html format
cdoMessage.TextBody := ABody; //Want to send in text format
cdoMessage.Send;
finally
VarClear(cdoMessage);
VarClear(cdoConfiguration);
end;
end;
可以将这些DLL文件作为资源包含在程序的可执行文件中,使用时将其导出到文件中,甚至可以通过重新定位代码并在内存中搜索入口点而无需首先导出它们。我有一些代码可以实现后者...