发送邮件和接收邮件的服务器 使用TNMSMTP控件在需认证服务器上发送邮件
使用TNMSMTP控件在需认证服务器上发送邮件
前言 现在很多STMP服务器在发送邮件时均需重新认证一遍 而Delphi的TNMSMTP控件对它没有很 可视化 的支持 使很多人在开发过程中大打问号
由于前段时间在做《CSDN查询助手》的时候 使用的也是需认证的服务器( ) 从其它地方摘取了部分代码得以解决 现在此发布与大家共享
实现
在NMSMTP的OnConnect事件中添加代码
var strUserName strPassword: String;begin strUserName := EncodeString( CoolSlob );//CoolSlob是服务器的帐号 strPassword := EncodeString( Password );//Password是密码 {进行认证 输入编码后的用户名 密码} nmsmtp Transaction( EHLO ) ; nmsmtp Transaction( AUTH LOGIN ); nmsmtp Transaction(strUserName); nmsmtp Transaction(strPassword); StatusBar SimpleText := 连接成功 ;end;
EncodeString函数实现过程
{对参数Decoded字符串进行Base 编码 返回编码后的字符串}function EncodeString(Decoded:string):String;var mmTemp mmDecoded:TMemoryStream; strTemp:TStrings;begin mmTemp := TMemoryStream Create; mmDecoded:=TMemoryStream Create; strTemp:=TStringList Create; strTemp Add(Decoded); strTemp SaveToStream(mmTemp); mmTemp Position := ; {剔除mmTemp从strTemp中带来的字符# # } mmDecoded CopyFrom(mmTemp mmTemp Size ); {对mmDecoded进行Base 编码 由mmTemp返回编码后的结果} EncodeBASE (mmTemp mmDecoded); {获得Base 编码后的字符串} mmTemp Position:= ; strTemp LoadFromStream(mmTemp); {返回结果必须从strTemp[ ]中获得 如果使用strTemp Text会 带来不必要的字符# # } Result:=strTemp[ ];end;
EncodeBASE 函数实现过程

function EncodeBASE (Encoded: TMemoryStream ; Decoded: TMemoryStream): Integer;const _Code : String[ ] = ( ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +/ );var I: LongInt; B: array[ ] of Byte; J K L M Quads: Integer; Stream: string[ ]; EncLine: String;begin Encoded Clear; Stream := ; Quads := ; {为提高效率 每 字节流为一组进行编码} J := Decoded Size div ; Decoded Position := ; {对前J* 个字节流进行编码} for I := to J do begin Decoded Read(B ); for M := to do begin for K := to do begin L:= *M + *K; Stream[Quads+ ] := _Code [(B[L] div )+ ]; Stream[Quads+ ] := _Code [(B[L] mod )* + (B[L+ ] div )+ ]; Stream[Quads+ ] := _Code [(B[L+ ] mod )* + (B[L+ ] div )+ ]; Stream[Quads+ ] := _Code [B[L+ ] mod + ]; Inc(Quads ); if Quads = then begin Stream[ ] := # ; EncLine := Stream+# # ; Encoded Write(EncLine[ ] Length(EncLine)); Quads := ; end; end; end; end;
{对以 为模的余数字节流进行编码} J := (Decoded Size mod ) div ; for I := to J do begin Decoded Read(B ); Stream[Quads+ ] := _Code [(B[ ] div )+ ]; Stream[Quads+ ] := _Code [(B[ ] mod )* + (B[ ] div )+ ]; Stream[Quads+ ] := _Code [(B[ ] mod )* + (B[ ] div )+ ]; Stream[Quads+ ] := _Code [B[ ] mod + ]; Inc(Quads ); {每行 个字符} if Quads = then begin Stream[ ] := # ; EncLine := Stream+# # ; Encoded Write(EncLine[ ] Length(EncLine)); Quads := ; end; end; { = 补位} if (Decoded Size mod ) = then begin Decoded Read(B ); Stream[Quads+ ] := _Code [(B[ ] div )+ ]; Stream[Quads+ ] := _Code [(B[ ] mod )* + (B[ ] div )+ ]; Stream[Quads+ ] := _Code [(B[ ] mod )* + ]; Stream[Quads+ ] := = ; Inc(Quads ); end;
if (Decoded Size mod ) = then begin Decoded Read(B ); Stream[Quads+ ] := _Code [(B[ ] div )+ ]; Stream[Quads+ ] := _Code [(B[ ] mod )* + ]; Stream[Quads+ ] := = ; Stream[Quads+ ] := = ; Inc(Quads ); end;
Stream[ ] := Chr(Quads); if Quads > then begin EncLine := Stream+# # ; Encoded Write(EncLine[ ] Length(EncLine)); end;
lishixinzhi/Article/program/Delphi/201311/25054相关文章
- 发送电子邮件通常用到的协议 在.NET 应用程序中用System.Web.Mail 发送电子邮件
- 电子邮件用到的协议 在电脑上发邮件用的是什么协议?
- 发送电子邮件用到的协议 SQLServer Job运行成功或失败时发送电子邮件通知的图文教程
- 工银融e联怎么设置登录密码 工行工银信使发送方式中的“APP推送消息”是什么?
- 手机邮件怎么发送邮件 使用ASP.NET两种发送邮件的方法
- smtp协议 邮件伺服器传送电子邮件是怎么一个过程?
- tcp服务器与客户端 分享socket 客户端-服务器入门代码
- 电脑有发送无接收数据 vs.net打造发送与接收端程序
- 手机邮件怎么发送邮件 在ASP.NET中使用SmtpMail发送邮件
- 使用飞信免费发短信给联通电信用户 联通可以登入飞信吗?
爱学记

微信收款码
支付宝收款码