欢迎来到 黑吧安全网 聚焦网络安全前沿资讯,精华内容,交流技术心得!

使用smtp发送邮件源码

来源:本站整理 作者:佚名 时间:2014-04-18 TAG: 我要投稿

 源文件:

#include 
#pragma hdrstop
#include "sendmail.h"
#include "mmsystem.h"
#pragma package(smart_init)
struct RecvEmailInfo
{
    AnsiString     strSubject, strFrom, strTo, strContent, strCmdDate, strCmdNum;
    int            nRecNum, nSendCount;
    TList         *AttachList;
};
struct AttachInfo
{
    AnsiString     FileName;
    int            Length;
    BYTE          *Content;
};
__fastcall TSendMailThread::TSendMailThread(bool CreateSuspended,int sleeptime )
 : TThread(CreateSuspended)
{
 Ftime           = sleeptime;
    FreeOnTerminate = true;
    nSendFlag       = -1;
    nCommandKind    = 0;
    strBoundary     = "----Mailor_of_qurqur.China----";
    RecvEmailList= new TList;
 
    /*TMemoryStream *ms = new TMemoryStream();
    ms->LoadFromFile( "d:\\test.txt" );
    RecvEmailInfo * pREI;
    AttachInfo * pAI;
    for( int i = 0; i < 5; i ++ )
    {
        pAI = new AttachInfo;
        pREI = new RecvEmailInfo;
        pAI->FileName = "test.txt";
        pAI->Length   = ms->Size;
        pAI->Content = new BYTE[ ms->Size ];
        ms->Position = 0;
        ms->ReadBuffer( pAI->Content, ms->Size );
        pREI->AttachList = new TList;
        pREI->AttachList->Add( pAI );
        pREI->strSubject = "humor";
        pREI->strFrom = "qurqur@163.net";
        pREI->strTo   = "qurqur@163.net;
        pREI->strContent = "test";
        pREI->nSendCount = 5;
        RecvEmailList->Add( pREI );
    }
    delete ms;*/
}
void __fastcall TSendMailThread::Execute()
{
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    wVersionRequested = MAKEWORD( 2, 2 );
    err = WSAStartup( wVersionRequested, &wsaData );
    if ( err != 0 )
    {
        // Tell the user that we could not find a usable WinSock DLL.
        return;
    }
    if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 )
    {
        // Tell the user that we could not find a usable WinSock DLL.
        WSACleanup( );
        return;
    }
    
 while( !Terminated )
    {
        if( !bCanSendEmail )
        {
            Sleep( Ftime );
            continue;
        }
        SendDeal();
        Sleep( 10 );
    }
}
int __fastcall TSendMailThread::InitSocket()
{
    smtpclient = socket( AF_INET, SOCK_STREAM, 0 );
    if( smtpclient == INVALID_SOCKET )
    {
        return -1;
    }
    HOSTENT* hostinfo = gethostbyname( strSMTPServer.c_str() );
    if( hostinfo == NULL )
        return -1;
    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_port = htons( nSMTPPort );
    memcpy( &server.sin_addr, *hostinfo->h_addr_list, sizeof( server.sin_addr ) );
    int rval = connect( smtpclient, ( struct sockaddr* )&server, sizeof( server ) );
    if( rval == SOCKET_ERROR )

[1] [2] [3] [4] [5] [6] [7] [8] [9]  下一页

【声明】:黑吧安全网(http://www.myhack58.com)登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们,联系邮箱admin@myhack58.com,我们会在最短的时间内进行处理。
  • 最新更新
    • 相关阅读
      • 本类热门
        • 最近下载