BCB中的发送邮件的例子

来源:互联网 发布:eve数据地点扫不到 编辑:程序博客网 时间:2024/06/08 06:00

来自csdn的   OnlyUx()

//--------------传到指定的邮箱------------------------
void __fastcall TfrmMain::SpeedButton1Click(TObject *Sender)
{
try
{  //::Sleep(100);
  Label2->Caption="正在登录服务器";
  IdMessage1->Recipients->EMailAddresses = "name1@163.com";     //邮件接收者的信箱
  IdMessage1->From->Text = "name2@sina.com";                    //邮件发送者的信箱
  IdMessage1->Subject =Memo1->Text;                             //邮件的标题
  IdMessage1->Body->Assign(Memo1->Lines);                       // 邮件的内容
if (IdSMTP1->Connected())
 {
    IdSMTP1->Disconnect();
 }
  IdSMTP1->AuthenticationType = atLogin; //登录服务器类型选择
  IdSMTP1->Host = "smtp.sina.com.cn";       //SMTP服务器
  IdSMTP1->UserId = "name2";              //邮箱的用户名
  IdSMTP1->Password = "name2@sina.com的密码";         //邮箱的密码
  IdSMTP1->Port = 25;                                        //端口
  IdSMTP1->Connect();                                      //连接SMTP服务器
  if (IdSMTP1->Authenticate())                         //用户验证
  {
    Label2->Caption="登录服务器验证成功";
    IdSMTP1->Send(IdMessage1);                   //发送邮件
    Label2->Caption="IP成功发送至name1@163.com";
  }

  IdSMTP1->Disconnect();
 }
 catch(...)
  {
  MessageBoxA(Handle,"请不要频繁发送","信息",0);
  return;
  }
}

原创粉丝点击