ورود

View Full Version : سوال: ارسال فایل به ایمیل



Mask
دوشنبه 24 مهر 1391, 21:22 عصر
با سلام.
من به راحتی به Gmail ایمیل ارسال میکنم.
میخاستم بدونم چطوری میشه یه فایل اتچ کرد و به ایمیل فرستاد؟
ممنون از پاسخگوییتون.

mohsen24000
دوشنبه 24 مهر 1391, 21:49 عصر
Smtp.AddAttachment()
http://delphi.about.com/library/weekly/code/src020304.zip
uses
SysUtils, IdSMTP, IdAttachment, IdMessage, IdMessageParts, IdEMailAddress, IdAttachmentFile;
var
IdMessage1: TIdMessage;
IdSMTP1: TIdSMTP;
Addressee: TIdEmailAddressItem ;
Attachment: TIdAttachment;
begin

IdMessage1 := TIdMessage.Create(nil);
IdSMTP1 := TIdSMTP.Create(nil);
IdSMTP1.Host := 'smtp.borland.com'; // SMTP server host name

IdMessage1.Body.Add('Hi Dear, this is the secret plans for Highlander that we talked about.');
IdMessage1.Subject := 'This message contains an attachment';
IdMessage1.From.Text := 'Gold@borland.com';
IdMessage1.From.Name := 'GOLD';

Attachment := TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\temp\HighlanderSecretPlans.zip');

Addressee := IdMessage1.Recipients.Add;
Addressee.Address := 'Mojtaba@borland.com'; // email address of recipient
Addressee.Name := 'Mojtaba';

IdSMTP1.Username := 'goldborland'; // SMTP user name
IdSMTP1.Password := '1234notgonnatellya'; // SMTP user password
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
IdSMTP1.Disconnect;

Attachment.Free;
IdMessage1.Free;
IdSMTP1.Free;

end.