Does anyone have a working code to send mail to Delphi
using Synapse? (with executables) On the Internet a lot of examples but not one does not send mail
- @Naruto, According to the rules of the forum, questions should not be limited to the decision or the completion of student assignments. Please clarify what you have done yourself and what did not work out. - Nicolas Chabanovsky ♦
|
1 answer
unit Unit5; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,httpsend, mimemess, mimepart, smtpsend,synachar; type TForm5 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; Edit1: TEdit; Button3: TButton; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} Procedure SendMail (Host, Subject, pTo, From , TextBody, HTMLBody, login,password : string); var Msg : TMimeMess; // сообщение StringList : TStringList; // содержимое письма MIMEPart : TMimePart; // части сообщения (на будущее) begin Msg := TMimeMess.Create; // создаем новое сообщение IdealCharsets:=[CP1251]; Msg.Header.CharsetCode:=CP1251; // Установим кодировку заголовков //{$IFNDEF CIL} //error URW778 ??? :-O //, GB2312, EUC_KR, ISO_2022_JP, EUC_TW {$ENDIF} ]; StringList := TStringList.Create; try // Добавляем заголовки Msg.Header.Subject := Subject;// тема сообщения Msg.Header.From := From; // имя и адрес отправителя Msg.Header.ToList.Add(pTo); // имя и адрес получателя // создаем корневой элемент MIMEPart := Msg.AddPartMultipart('alternative', nil); if length(TextBody)=0 then // если формат HTML begin StringList.Text := HTMLBody; Msg.AddPartHTML(StringList, MIMEPart); end else // если текстовый формат begin StringList.Text := TextBody; Msg.AddPartText(StringList, MIMEPart); end; // Кодируем и отправляем Msg.EncodeMessage; // Отправляем. if smtpsend.SendToRaw(From,pTo,Host,Msg.Lines,login,password) then ShowMessage('Письмо отправлено') else ShowMessage('Письмо не отправлено'); finally Msg.Free; StringList.Free; end; end; procedure TForm5.Button1Click(Sender: TObject); begin SendMail('smpt.yandex.com', 'tema testovogo pisma', 'test@mail.ru', 'test@yandex.ru', 'Soderzhimoe pisma v textovom formate', '', 'test', '**********') end; end.
- @Naruto; To format a code, select it with the mouse and click on the {} button of the editor. - Deleted
|