отправка Email письма через компонент IdTCPClient

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by bertys, 15 Feb 2012.

  1. bertys

    bertys New Member

    Joined:
    25 Jan 2012
    Messages:
    162
    Likes Received:
    0
    Reputations:
    0
    Здравствуйте форумчане, вот есть код для отправки письма на мыло через компонент IdTCPClient, все отлично пашет, но хотелось бы дописать от кого пришло, тоесть чтоб в поле от кого был не маил а имя, как это сделать???

    Вот код отправки:

    PHP:
    var
      
    tsString;
      
    iInteger;

      
    sBoundaryString;
    begin
      EnableControls
    (false);
      try
        
    IdTCPClient.Host:=edServer.Text;
        
    IdTCPClient.Port:=sedPort.Value;
        
    IdTCPClient.Connect;
        
    IdTCPClient.GetResponse([220]);
        
    LogAllIncoming;

        
    LogOutcoming('Отправка');
        
    IdTCPClient.SendCmd('HELO StudForum.ru'250);
        
    LogAllIncoming;

        if 
    cbAuthetication.Checked then
          begin
            LogOutcoming
    ('AUTH LOGIN');
            
    IdTCPClient.SendCmd('AUTH LOGIN'334);
            
    LogAllIncoming;

            
    ts:=MimeEncodeString(edLogin.Text);
            
    LogOutcoming(ts);
            
    IdTCPClient.SendCmd(ts334);
            
    LogAllIncoming;

            
    ts:=MimeEncodeString(edPassword.Text);
            
    LogOutcoming(ts);
            
    IdTCPClient.SendCmd(ts235);
            
    LogAllIncoming;
          
    end;

        
    LogOutcoming('MAIL FROM:<'+edRetAddress.Text+'>');
        
    IdTCPClient.SendCmd('MAIL FROM:<'+edRetAddress.Text+'>'250);
        
    LogAllIncoming;

        
    LogOutcoming('RCPT TO:<'+edTo.Text+'>');
        
    IdTCPClient.SendCmd('RCPT TO:<'+edTo.Text+'>', [250251]);
        
    LogAllIncoming;

        
    LogOutcoming('DATA');
        
    IdTCPClient.SendCmd('DATA'354);
        
    LogAllIncoming;

        
    LogOutcoming('X-Mailer: Email advertising ');
        
    IdTCPClient.WriteLn('X-Mailer: Email advertising ');

        
    LogOutcoming('From: '+edRetAddress.Text);
        
    IdTCPClient.WriteLn('From: '+edRetAddress.Text);

        
    LogOutcoming('To: '+edTo.Text);
        
    IdTCPClient.WriteLn('To: '+edTo.Text);

        if 
    lvAttachments.Items.Count 0 then
          begin
          
    if checkbox3.Checked=true then
           begin
            LogOutcoming
    ('MIME-Version: 1.0'#13#10'Content-Type: multipart/mixed; text/html; boundary="'+sBoundary+'"');
            
    IdTCPClient.WriteLn('MIME-Version: 1.0'#13#10'Content-Type: multipart/mixed; text/html; boundary="'+sBoundary+'"');
           
    end
           
    else
           
    begin
            sBoundary
    :='StudMailer_by_StudForum.RU';
            
    LogOutcoming('MIME-Version: 1.0'#13#10'Content-Type: multipart/mixed; boundary="'+sBoundary+'"');
            
    IdTCPClient.WriteLn('MIME-Version: 1.0'#13#10'Content-Type: multipart/mixed; boundary="'+sBoundary+'"');
          
    end;
          
    end
        
    else
          
    begin
           
    if checkbox3.Checked=true then
           begin
            LogOutcoming
    ('MIME-Version: 1.0'#13#10'Content-Type: text/html; charset=windows-1251');
            
    IdTCPClient.WriteLn('MIME-Version: 1.0'#13#10'Content-Type: text/html; charset=windows-1251');
           
    end
           
    else
           
    begin
            LogOutcoming
    ('MIME-Version: 1.0'#13#10'Content-Type: text/plain; charset=windows-1251');
            
    IdTCPClient.WriteLn('MIME-Version: 1.0'#13#10'Content-Type: text/plain; charset=windows-1251');
            
    end;
          
    end;


        
    LogOutcoming('Subject: '+edSubj.Text+#13#10#13#10);
        
    IdTCPClient.WriteLn('Subject: '+edSubj.Text+#13#10);

        
    if lvAttachments.Items.Count 0 then
          begin
            LogOutcoming
    ('--'+sBoundary+#13#10#13#10);
            
    IdTCPClient.WriteLn('--'+sBoundary+#13#10);
          
    end;


       
         
    begin
         LogOutcoming
    (memText.Text);
         
    IdTCPClient.WriteLn(memText.Text);
         
    end;

        for 
    i:=0 to lvAttachments.Items.Count-do
          
    begin
            LogOutcoming
    ('--'+sBoundary);
            
    IdTCPClient.WriteLn('--'+sBoundary);


            
    LogOutcoming('Content-Type: application/octet-stream; name="'+lvAttachments.Items[i].Caption+'"'#13#10+
    'Content-Disposition: attachment; filename="'+lvAttachments.Items[i].Caption+'"'#13#10+
    'Content-Transfer-Encoding: base64'#13#10#13#10);
            
    IdTCPClient.WriteLn('Content-Type: application/octet-stream; name="'+lvAttachments.Items[i].Caption+'"'#13#10+
    'Content-Disposition: attachment; filename="'+lvAttachments.Items[i].Caption+'"'#13#10+
    'Content-Transfer-Encoding: base64'#13#10);

            
    ts:=MimeEncodeString(ReadFileIntoString(lvAttachments.Items[i].SubItems[0]));
            
    LogOutcoming(ts);
            
    IdTCPClient.WriteLn(ts);
          
    end;                  

        
    LogOutcoming('.');
        
    IdTCPClient.SendCmd('.'250);
        
    LogAllIncoming;

        
    LogOutcoming('QUIT');
        
    IdTCPClient.WriteLn('QUIT');
      finally
        
    IdTCPClient.Disconnect;
        
    EnableControls(true);
      
    end;
    end;


    Зарание спасибо
     
  2. Chrome~

    Chrome~ Elder - Старейшина

    Joined:
    13 Dec 2008
    Messages:
    937
    Likes Received:
    162
    Reputations:
    27
    Точно не помню, но может быть так должно быть:
    Code:
    IdTCPClient.WriteLn('From: Имя отправителя <'+edRetAddress.Text+'>');
     
  3. bertys

    bertys New Member

    Joined:
    25 Jan 2012
    Messages:
    162
    Likes Received:
    0
    Reputations:
    0
    я так тоже думал, о выдавало ошибку, позже выложу ее скрин
     
  4. bertys

    bertys New Member

    Joined:
    25 Jan 2012
    Messages:
    162
    Likes Received:
    0
    Reputations:
    0
    Сделал так:


    Выдает вот эту ошибку:

    [​IMG]


    А когда сделал так:


    То такая ошибка:

    [​IMG]
     
    #4 bertys, 20 Feb 2012
    Last edited: 20 Feb 2012