Rah*_*han 5 android sendgrid-api-v3
我能够发送带有单个附件的电子邮件,但我找不到在单个邮件中发送多个附件的任何内容
try {
SendGrid sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD);
SendGrid.Email email = new SendGrid.Email();
// Get values from edit text to compose email
// TODO: Validate edit texts
email.addTo(mTo);
email.setFrom(mFrom);
email.setSubject(mSubject);
email.setText(mText);
// Attach image
if (mUri != null) {
email.addAttachment(mAttachmentName, mAppContext.getContentResolver().openInputStream(mUri));
}
// Send email, execute http request
SendGrid.Response response = sendgrid.send(email);
mMsgResponse = response.getMessage();
Log.d("SendAppExample", mMsgResponse);
} catch (SendGridException | IOException e) {
Log.e("SendAppExample", e.toString());
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
小智 0
$files = ['/home/pawr/testAttach1.txt','/home/pawr/testAttach2.txt'];
foreach($files as $f) {
// create attachment and add to email
$fn = $this->createSendGridAttachment($f);
$email->addAttachment($fn);
}
// code in custom function createSendGridAttachment($file_path)
{
// Note, you may need to use different encoding methods for setContent() and
// MIME types with setType() depending on your use case.
$content = file_get_contents($file_path);
$content = base64_encode($content);
$attachment = new \SendGrid\Mail\Attachment();
$attachment->setContent($content);
$attachment->setFilename(basename($file_path));
return $attachment;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3484 次 |
| 最近记录: |