2010年12月22日水曜日

delphi indy で smtp 備忘録

参考URL:http://hpcgi1.nifty.com/MADIA/DelphiBBS/wwwlng.cgi?print+200911/09110030.txt

MECSUtils は、こちら

uses ..., IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, IdMessage,
  IdEMailAddress, MECSUtils;

...

procedure THoge.SendMail(title:string; desc :string);
var
  msg: TIdMessage;
  mItem: TIdEMailAddressItem;
begin
  IdSmtp1.AuthType := satNone;
  IdSmtp1.Host := 'mail.yourcorp.co.jp';
  IdSmtp1.Username := 'login@yourcopr.co.jp';
  IdSmtp1.Password := 'password';
  IdSmtp1.Port := 25;
  msg := TIdMessage.Create();
  try
    msg.ContentType := 'text/plain';
    msg.CharSet := 'ISO-2022-JP';
    msg.ContentTransferEncoding := '7bit';
    msg.From.Name := 'なんちゃら監視サービス';
    msg.From.Address := 'daemon@yourcorp.co.jp';
    mItem := msg.Recipients.Add();
    mItem.Name    := '管理者さま';
    mItem.Address := 'to@yourcorp.co.jp';
    msg.Subject := MecsMappingFix_UnicodeToJISX0208( title );
    msg.Body.Add( MecsMappingFix_UnicodeToJISX0208( desc ) );
    IdSmtp1.Connect;
    IdSmtp1.Send(msg);
    IdSmtp1.Disconnect;
  finally
    msg.Free;
  end;
end;

0 件のコメント: