[Email] Email介紹(二)

來源出處:
http://xdeath.dyndns.pro/read.php?62

以PHP的範例來說就像下面這樣

        function mailto($from,$to,$subject,$msg,$filename=")
  {
    $mailto = “;
    if(count($to) > 1)
      for($i = 0;$i < count($to);$i++)
        $mailto .= “$to[$i],";
    else
      $mailto = $to;
    $boundary = uniqid(“"); // 產生分隔字串 
    $subject = ‘=?utf-8?B?’.base64_encode(“$subject").’?=’; // 標題加密(防亂碼) 
    $headers = “; 
    $headers .= “MIME-Version: 1.0\r\n"; 
    $headers .= “Content-type: multipart/mixed; boundary=\"$boundary\"; charset=\"UTF-8\"\r\n"; //宣告分隔字串 
    $headers .= ‘From:’.$from."\r\n"; // 設定寄件者 
    $headers .= “X-Mailer: PHP/".phpversion()."\r\n"; 
    $body .= “–$boundary\r\n"; 
    $body .= “Content-type: text/plain; charset=\"UTF-8\"\r\n";// 信件本文header 
    $body .= “Content-Transfer-Encoding: 8bit\r\n\r\n";// 信件本文header 
    $body .= $msg."\r\n"; // 本文內容 
    //附加檔案處理
    if(!is_array($filename))
      $files[0] = $filename;
    if( count($files) != 0)
    {   
      for($i = 0;$i < count($files);$i++)
      { 
        $mimeType = mime_content_type($files[$i]); // 判斷檔案類型 ,php.ini要開啟php_mime_magic.dll
        if(!$mimeType)
          $mimeType = “application/unknown"; // 若判斷不出則設為未知 
        $data = chunk_split(base64_encode(file_get_contents($files[$i])));
        $file = basename($files[$i]); //傳回不包含路徑的檔案名稱(mail中會顯示的檔名)
        $body .= “–$boundary\r\n"; 
        $body .= “Content-type: $mimeType; name=$file\r\n"; 
        $body .= “Content-transfer-encoding: base64\r\n"; 
        $body .= “Content-disposition: attachment; filename=$file\r\n\r\n"; 
        $body .= “$data\r\n"; 
      }
    }
    $body .= “–$boundary–“;//郵件結尾
    mail($mailto, $subject, $body, $headers); // 寄出信件
  }

perl範例

sub mailto
{
    my ($from,$to,$title,$content,$file) = @_;
    my $id = “;
    for(my $i = 0;$i <= 20;$i++){$id .= chr(97 + int(rand(26)));}
    $title = ‘=?utf-8?B?’.substr(encode_base64($title),0,-1).’?=’;
    my $header = “X-Priority: 3\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 8bit\r\nContent-type: text/html;charset=utf-8
Content-type: multipart/mixed; boundary=\"$id\"; charset=\"UTF-8\"\r\nFrom: $from\r\nSubject: $title\r\nTo: $to\r\n–$id
Content-type: text/plain; charset=\"UTF-8\"\r\nContent-Transfer-Encoding: 8bit\r\n\r\n";
    #夾檔
    if($file ne “){
        my $filename = basename($file);
        my $data = encode_base64(`cat $filename`);
        $content .= “\r\n\r\n–$id\r\nContent-type: application/unknown;name=$filename\r\nContent-transfer-encoding: base64
Content-disposition: attachment; filename=$filename\r\n\r\n$data";
    }
    $content .= “–$id–“;
    open(MM,"|/usr/lib/sendmail -oem -oi -f ‘$from’ -t ‘$to'");
    print MM “$header$content";
    close(MM);
}

[Delphi] 用Indy的TIdSMTP发送HTML格式的邮件,并且带附件

來源出處:
https://bbs.csdn.net/topics/80114188

procedure TFormMain.SendMail(Recipient, Address: string);
const
  sStars = ‘BackgroundStars.jpg’;
var
  AdressItem: TIdEMailAddressItem;
  AFile: string;
  AMessage: TIdMessage;
  ASMTP: TIdSMTP;
  AStream: TMemoryStream;
  Attachment: TIdAttachment;
  IdBody: TIdText;
  IdHTML: TIdText;
  idStars: TIdAttachment;
  resStars: TStream;
  TempFile: TStream;
begin
  Screen.Cursor := crHourGlass;
  AFile := FileListBox.FileName;
  if FileExists(AFile) then begin
    AMessage := TIdMessage.Create(nil);
    AMessage.NoDecode := False;
    AMessage.NoEncode := False;
    AMessage.ContentType := ‘multipart/mixed’;
    AMessage.Encoding := meMIME;
    AMessage.MsgId := ‘PrettyPic’;
    AMessage.References := ChangeFileExt(ExtractFileName(AFile), “);
    // Set recipients.
    AdressItem := AMessage.Recipients.Add;
    AdressItem.Name := Recipient;
    AdressItem.Address := Address;
    // Set subject.
    AMessage.Subject := ‘Hello.’;
    // Set sender.
    AMessage.Sender.Name := ‘Workshop Alex’;
    AMessage.Sender.Address := ‘someone@somewhere.org’;
    // Set from.
    AMessage.From.Name := AMessage.Sender.Name;
    AMessage.From.Address := AMessage.Sender.Address;
    // Create plain body.
    IdBody := TIdText.Create(AMessage.MessageParts);
    IdBody.ContentType := ‘text/plain’;
    IdBody.Body.Add(‘Hello, friends.’);
    IdBody.Body.Add(“);
    // Add more to the plain-text bodypart.
    // Create HTML body.
    IdHTML := TIdText.Create(AMessage.MessageParts);
    IdHTML.ContentType := ‘text/html; charset=US-ASCII’;
    IdHTML.ContentTransfer := ‘7bit’;
    IdHTML.Body.Add(‘<html>’);
    IdHTML.Body.Add(‘  <head>’);
    IdHTML.Body.Add(‘    <title>Hello</title>’);
    IdHTML.Body.Add(‘  </head>’);
    IdHTML.Body.Add(‘  <body title="‘ + AMessage.References + ‘" background="cid:BackgroundStars">’);
    IdHTML.Body.Add(‘    Hello, friends.<br>’);
    IdHTML.Body.Add(‘    <br>’);
    IdHTML.Body.Add(‘    <img src="cid:PrettyPic" alt="‘ + ExtractFileName(AFile) + ‘" name="‘ + ExtractFileName(AFile) + ‘" title="Just an image included.">’);
    IdHTML.Body.Add(‘  </body>’);
    IdHTML.Body.Add(‘</html>’);
    // Add the attachment. Don’t forget the extra headers!
    Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
    Attachment.ExtraHeaders.Values[‘Content-ID’] := ‘<PrettyPic>’;
    Attachment.ContentType := ‘image/jpeg’;
    idStars := TIdAttachment.Create(AMessage.MessageParts, ExtractFilePath(ParamStr(0)) + sStars);
    idStars.ExtraHeaders.Values[‘Content-ID’] := ‘<BackgroundStars>’;
    idStars.ContentType := ‘image/jpeg’;
    // Now send the thing…
    ASMTP := TIdSMTP.Create(nil);
    ASMTP.Host := ‘mail.whatever.org’;
    ASMTP.Port := 25;
    ASMTP.AuthenticationType := atNone;
    ASMTP.Connect;
    try
      ASMTP.Send(AMessage);
    except
      on E: Exception do ShowMessageFmt(‘Error: %s’, [E.Message]);
    end;
    ASMTP.Disconnect;
    AMessage.Free;
    ASMTP.Free;
  end;
  Screen.Cursor := crDefault;
end;

[Delphi] 如何用DELPHI實現把WORD、EXCEL和圖片等儲存到資料庫中

來源出處:
https://www.itread01.com/content/1548048812.html

用image欄位儲存這些文件。   
  var   
      word_stream:   TMemoryStream;   
      filename:   string;   
  begin   
      if   odgDoc.Execute   then//odgDoc:OpenDialog   
      begin   
          filename   :=   ExtractFileName(odgDoc.FileName);   
          word_stream   :=   TMemoryStream.Create;   
          word_stream.LoadFromFile(odgDoc.FileName);   
          word_stream.Position   :=   0;   
          cdsPACT.Append   
          cdsPACT.FieldByName(‘DocName’).Value   :=   filename;   
          TBlobField(cdsPACT.FieldByName(‘PactText’)).LoadFromStream(word_stream);   
          cdsPACT.Post;   
          word_stream.Free;   
      end;   
  end; 

[OpenSSL] OpenSSL存在旁路攻擊漏洞,光靠攔截手機電磁訊號就能取得金鑰

來源出處:
https://www.ithome.com.tw/news/125370

研究人員發現透過OpenSSL旁路攻擊,截取裝置在電子活動中所產生的各種訊號,例如電磁輻射、功耗變化,甚至是聲音、溫度等變化,從中擷取出金鑰。

[Delphi] Indy 10 Lazarus/FreePascal Port

來源出處:
http://ww2.indyproject.org/Sockets/fpc/index.EN.aspx

Downloads

Download source from the Development Snapshot and extract the source files to a folder of your choosing on your PC.

An older code from the version control system that was organized into a sensible distribution.  This was last updated on Nov 13 2007.  Please read the README file included with this distribution.

We also distribute OpenSSL for Win64 so you can use Indy’s OpenSSL support in your Windows 64-bit software.

[Delphi] How do I add attachments to email using Indy?

來源出處:
https://support.embarcadero.com/article/36054

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 Chee Wee, this is the secret plans for Highlander that we talked about.’);
� IdMessage1.Subject := ‘This message contains an attachment’;
� IdMessage1.From.Text := ‘Frank_Borland@borland.com’;
� IdMessage1.From.Name :=� ‘Frank Borland’;

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

� Addressee := IdMessage1.Recipients.Add;
� Addressee.Address := ‘Chee_Wee_Chua@borland.com’; // email address of recipient
� Addressee.Name := ‘Chee Wee Chua’;

� IdSMTP1.Username := ‘frankborland’; // SMTP user name
� IdSMTP1.Password := ‘1234notgonnatellya’; // SMTP user password
� IdSMTP1.Connect;
� IdSMTP1.Send(IdMessage1);
� IdSMTP1.Disconnect;

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

end.