aws傳送郵件只能傳送不帶附件的,可以直接調方法sendemail,但是傳送帶附件的郵件,用sendrawemail必須自己寫mime郵件格式的郵件,不像sendemail那樣方便
/**
* 傳送帶附件的郵件
* @param array $toemaillist 目標郵箱組
* @param string $sendcontent 郵件正文
* @param string $sender 傳送人
* @param string $attachment 附件檔案內容
* @param string $attachmentname 附件檔名
* @param string $attachmenttype 附件型別
* @return integer
* @throws \exception
*/$emailconfig = [
'key' => '替換自己的',
'secret' => '替換自己的',
'region' => 'us-east-1',
'sender' => '預設的傳送人',
];$fromemail = $sender ?: $emailconfig["sender"];
preg_match('/(.*)<\/title>/', $sendcontent, $match);
$subject = $match[1];
$credentials = new credentials($emailconfig['key'], $emailconfig['secret']);
$sesclient = new sesclient([
'version' => 'latest',
'region' => $emailconfig['region'],
'credentials' => $credentials,
]);//build the message
if (is_array($toemaillist)) else
$boundary = uniqid("_part_" . time(), true); //random unique string
$msg =
"to: $toemailstr\n" .
"from: $fromemail\n" .
"subject: $subject\n" .
"mime-version: 1.0\n" .
"content-type: multipart/alternative;\n" .
" boundary=\"$boundary\"\n" .
"content-transfer-encoding: 8bit\n" .
"\n" .
"this is a multi-part message in mime format.\n" .
"\n" .
"--$boundary\n" .
"content-type: text/plain; charset=utf-8\n" .
"\n" .
strip_tags($sendcontent) . "\n" .
"\n" .
"\n" .
"--$boundary\n" .
"content-type: text/html; charset=utf-8\n" .
"\n" .
"$sendcontent\n" .
"\n" .
"\n" .
"\n" .
"--$boundary";
//add attachments
if (!empty($attachment))
//close email
$msg .= "--" . "\n";
//now send the email out
try catch (aw***ception $e)
return $messageid;
}
用python傳送郵件(可以帶附件)
首先,我們要使用smtp mail transfer protocol,簡單郵件傳輸協議 使用到python的smtplib模組 smtp,login,sendmail,quit email.mime模組 mimemultipart,mimebase等 from email.mime import ...
php簡單實現傳送帶附件的郵件
下面是靜態html 帶附件的郵件傳送 sendmail.php檔案 from post from to post to subject post subje程式設計客棧ct body post body 定義分界線 boundary 345894369383 分界線是一串無規律的字元 設定heade...
python傳送帶附件郵件
1.不包括附件的郵件 coding utf 8 import smtplib import string 傳送普通的文字郵件 郵件smtp的位址 host smtp.163.com 定義郵件的標題 subject 這是郵件標題 發件人 from 163.com 收件人 to qq.com 傳送的郵件...