我正在使用https://github.com/Webklex/laravel-imap从我的邮件服务器检索电子邮件。
现在我需要转发包含所有正文(文本、html、附件)的确切邮件。我如何转发电子邮件?
发布于 2021-10-19 16:12:54
我也在做同样的事情,我想给出一个与使用Laravel-IMAP获取电子邮件然后转发它们相关的更具体的答案。
See this answer which helped out a lot.
use Illuminate\Mail\Mailable;
public function build()
{
$this->view('emails.emails.received')->with('body', $this->message->getHTMLBody())
->from($this->message->getFrom()->first()->mail, $this->message->getFrom()->first()->personal)
->to('<forwarded_email>')
->replyTo($this->message->getReplyTo()->first()->mail, $this->message->getReplyTo()->first()->personal)
->subject($this->message->getSubject());
foreach ($this->message->getAttachments() as $attachment) {
$this->attach($attachment);
}
$this->withSwiftMessage(function ($msg) {
$msg->getHeaders()->addTextHeader('In-Reply-To', $this->message->getMessageId());
$msg->getHeaders()->addTextHeader('references', $this->message->getReferences());
});
return $this;
}此外- My template emails.emails.received仅包含以下内容:{!! $body !!}
发布于 2020-06-14 07:33:41
当然,这是可能的,我建议您使用:Laravel Mail Auto Embed
它的用法非常简单,你可以正常地写下你的markdown:
<!-- eg: resources/vendor/mail/markdown/order-shipped.blade.php -->
@component('mail::message')
# Order Shipped
Your order has been shipped!
@component('mail::button', ['url' => $url])
View Order
@endcomponent
Purchased product:

Thanks,<br>
{{ config('app.name') }}
@endcomponent当您发送电子邮件时,它将替换内联数据的url图像,这是处理和转发电子邮件最简单的方式。
发送时,它将替换通常会生成的链接:
<img src="https://example.com/products/product-1.png">
by an embedded inline attachment of the image:
<img src="cid:3991f143cf1a86257f8671883736613c@Swift.generated">发布于 2020-06-15 08:41:20
我会给你一个想法
首先,您需要从laravel-imap中获取电子邮件数据,并将其存储在一个变量中
首先,您需要指定所需的消息,假设您正在查找包含特定信息的消息,可以这样指定
foreach($aFolder as $oFolder){
//Get all messages by custom search criteria
/** @var \Webklex\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->query()->where(["CUSTOM_Word" => "Hello"]])->get();
}现在,您有了一个包含其所有组件的特定电子邮件
现在将其发送到所需的电子邮件或电子邮件列表(使用foreach)
将$aMessage变量传递给发送函数,然后
$receiver_email = 'john@gmail.com';
$data = array ('subject' => '$aMessage->getSubject().'<br />'' ,
'Attachments' => '$aMessage->getAttachments()->count().'<br />'',
'body' => '$aMessage->getHTMLBody(true)';
)
Mail::send('emails.message', $data, function ($message) {
$message->to($receiver_email)
->subject($aMessage->getSubject());
$message->from('youremail@app.com' , 'your name')
});在您的电子邮件/消息中,不要忘记将带有主题、附件和正文的自定义消息作为输出
在电子邮件/消息中,它将是将发送到客户端的消息,您可以使用html、css进行设计,就像使用laravel刀片模板的任何其他文件一样。以下是来自Medium的示例
Hello <strong>{{ $subject}}</strong>
<p>{{$body}}</p>注意:你可能会发现一些打字错误或错误,因为就像我告诉你的那样,我给了你想法,但不能给你你想要的东西。
here你可以找到另一个关于发送电子邮件的问题,你可能想看看它
https://stackoverflow.com/questions/62329458
复制相似问题