标签: email-attachments

通过SMTP发送带附件,纯文本/文本和文本/ hml的电子邮件

我的目标:使用普通/文本,文本/ html和附件通过SMTP发送交易电子邮件.

我的代码:用JavaMail实现

我的问题:它在hotmail或outlook上看起来很好.但是在gmail上,如果它是带有.txt附件的电子邮件,它就不会正确显示邮件正文(如果附件是图像,它可以正常工作)

任何帮助将受到高度赞赏.

这是我的原始SMTP输出:

Subject: ALTERNATIVE | TXT | HTML |ATT.ATTACHMENT | Thu Jun 13 17:48:04 EDT
 2013
MIME-Version: 1.0
Content-Type: multipart/alternative; 
    boundary="----=_Part_0_21791733.1371160084561"

------=_Part_0_21791733.1371160084561
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Body message in text format!
------=_Part_0_21791733.1371160084561
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

Body message in <b>html</b> format! Sent on Thu Jun 13 17:48:04 EDT 2013<br> to: me@gmail.com<br> to: me@mijo.com<br> cc: me@hotmail.com<br> cc: rafael.santos.test@hotmail.com
------=_Part_0_21791733.1371160084561
Content-Type: text/plain; charset=us-ascii; name=email_attachment.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=email_attachment.txt

This is …
Run Code Online (Sandbox Code Playgroud)

email smtp jakarta-mail html-email email-attachments

11
推荐指数
1
解决办法
3万
查看次数

无法将javascript文件作为电子邮件附件发送

Hotmail不允许将javascript文件附加到电子邮件中,背后的原因是什么?

javascript email email-attachments

11
推荐指数
1
解决办法
2万
查看次数

Codeigniter发送带附件的电子邮件

我正在尝试使用附加文件在codeigniter上发送电子邮件.

我总是成功收到电子邮件.但是,我从未收到过附件.以下是代码,非常感谢所有评论.

    $ci = get_instance();
    $ci->load->library('email');
    $config['protocol'] = "smtp";
    $config['smtp_host'] = "ssl://smtp.gmail.com";
    $config['smtp_port'] = "465";
    $config['smtp_user'] = "test@gmail.com";
    $config['smtp_pass'] = "test";
    $config['charset'] = "utf-8";
    $config['mailtype'] = "html";
    $config['newline'] = "\r\n";

    $ci->email->initialize($config);

    $ci->email->from('test@test.com', 'Test Email');
    $list = array('test2@gmail.com');
    $ci->email->to($list);
    $this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
    $ci->email->subject('This is an email test');
    $ci->email->message('It is working. Great!');

    $ci->email->attach( '/test/myfile.pdf');
    $ci->email->send();
Run Code Online (Sandbox Code Playgroud)

php email codeigniter email-attachments

11
推荐指数
2
解决办法
6万
查看次数

如何删除图像作为附件,但显示在电子邮件正文中

我找到了这个解决方案,用于在电子邮件正文中显示图像: 将图像添加到电子邮件正文中

它工作正常,但它也添加图像作为电子邮件的附件.

Attachment inlineLogo = new Attachment(EmailLogo.ImageUrl);
mailMsg.Attachments.Add(inlineLogo);
string contentID = "Image";
inlineLogo.ContentId = contentID;

//To make the image display as inline and not as attachment
inlineLogo.ContentDisposition.Inline = true;
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;

//To embed image in email
mailMsg.Body = "<htm><body> <img height=\"49\" width=\"169\" src=\"cid:" + contentID + "\"> </body></html>";
Run Code Online (Sandbox Code Playgroud)

有一行代码,评论显示为内联而非附件,但此行无法正常工作,因为图片仍会附加到电子邮件中:

//To make the image display as inline and not as attachment
inlineLogo.ContentDisposition.Inline = true;
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
Run Code Online (Sandbox Code Playgroud)

如何阻止图像附加到电子邮件?

c# asp.net email email-attachments

11
推荐指数
2
解决办法
2656
查看次数

Mailgun已发送邮件附件

当邮件有使用mailgun发送的附件时,我正面临问题.如果有人做过这件事,请回复.这是我的代码......

$mg_api = 'key-3ax6xnjp29jd6fds4gc373sgvjxteol0';
$mg_version = 'api.mailgun.net/v2/';
$mg_domain = "samples.mailgun.org";
$mg_from_email = "info@samples.com";
$mg_reply_to_email = "info@samples.org";

$mg_message_url = "https://".$mg_version.$mg_domain."/messages";


$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_USERPWD, 'api:' . $mg_api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, true); 
//curl_setopt($curl, CURLOPT_POSTFIELDS, $params); 
curl_setopt($ch, CURLOPT_HEADER, false); 

//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $mg_message_url); …
Run Code Online (Sandbox Code Playgroud)

php email email-attachments mailgun

10
推荐指数
2
解决办法
2万
查看次数

使用Swift实施应用内电子邮件失败

我想使用swift来实现应用内电子邮件.单击该按钮时,会弹出电子邮件窗口.但是,我无法发送电子邮件.此外,点击取消删除草稿后,我无法返回到原始屏幕.

import UIkit
import MessageUI


class Information : UIViewController, MFMailComposeViewControllerDelegate{

    var myMail: MFMailComposeViewController!

    @IBAction func sendReport(sender : AnyObject) {

        if(MFMailComposeViewController.canSendMail()){
            myMail = MFMailComposeViewController()

            //myMail.mailComposeDelegate

            // set the subject
            myMail.setSubject("My report")

            //To recipients
            var toRecipients = ["lipeilin@gatech.edu"]
            myMail.setToRecipients(toRecipients)

            //CC recipients
            var ccRecipients = ["tzhang85@gatech.edu"]
            myMail.setCcRecipients(ccRecipients)

            //CC recipients
            var bccRecipients = ["tzhang85@gatech.edu"]
            myMail.setBccRecipients(ccRecipients)

            //Add some text to the message body
            var sentfrom = "Email sent from my app"
            myMail.setMessageBody(sentfrom, isHTML: true)

            //Include an attachment
            var image = UIImage(named: "Gimme.png")
            var imageData = …
Run Code Online (Sandbox Code Playgroud)

email-attachments ios swift mfmailcomposeviewcontroller

10
推荐指数
1
解决办法
4736
查看次数

Gmail会在HTML电子邮件的图片上显示下载图标

我们有一个Html Builder,允许您为电子邮件创建响应式HTML.我们正在使用第三方引擎批量发送电子邮件.问题是,当电子邮件在Gmail收件箱正在运行结束,它显示一些图像(不是全部)的下载图标,而相对于没有下载图标的图像时,其生成的html是一样的.

悬停下载图标

为什么gmail会在电子邮件中添加图像的下载图标.看起来像处理图像像附件.任何信息,修复或建议表示赞赏?这是我们发送的生成的html-

<table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" class="bodyContainer">
    <tr>
        <td align="center" valign="top" >
            <table border="0" cellspacing="0" cellpadding="0" class="emailContainer">
                <tr>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td style="text-align: center; padding: 0px;">
                                                <img src="http://img.xyz.net/gallery/212aeedd-2672-4960-a81c-8b78635c8fd9/firsthalf.jpg" width="598" border="0" style="max-width: 600px;" hspace="0" vspace="0">
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td style="text-align: center; padding: 0px;">
                                                <img src="http://img.xyz.net/gallery/212aeedd-2672-4960-a81c-8b78635c8fd9/secondhalf.jpg" width="300" border="0"style="max-width: 300px;" hspace="0" vspace="0"> …
Run Code Online (Sandbox Code Playgroud)

email gmail email-client html-email email-attachments

10
推荐指数
2
解决办法
1万
查看次数

带有长非ascii名称的电子邮件附件

我尝试发送System.Net.Mail.MailMessageSystem.Net.Mail.Attachment.

附件名称是"Счёт-договор№4321от4июля.pdf"

附件创建代码:

var nameEncoding = Encoding.UTF8;
return new System.Net.Mail.Attachment(new MemoryStream(bytes), 
                                      MessageBodiesHelpers.EncodeAttachmentName(fileName, nameEncoding),
                                      attachment.MediaType)
       {
            TransferEncoding = TransferEncoding.Base64,
            NameEncoding = nameEncoding
       };
Run Code Online (Sandbox Code Playgroud)

代码内容MessageBodiesHelpers.EncodeAttachmentName取自https://social.msdn.microsoft.com/Forums/en-US/b6c764f7-4697-4394-b45f-128a24306d55/40-smtpclientsend-attachments-mit-umlauten-im-dateinamen?forum=dotnetframeworkde

如果我将该附件发送到gmail或ms exchange,则附件名称已成功解码.但!

如果我将附件发送到icloud,那么我会得到"???? - ???????№4321от4????.pdf"

邮件附件标题:

来自ms exchange:

Content-Type: application/pdf;
    name="=?utf-8?B?0KHRh9GR0YIt0LTQ?==?utf-8?B?vtCz0L7QstC+0YAg?==?utf-8?B?4oSWNDMyMSDQvtGC?==?utf-8?B?IDQg0LjRjtC70Y8u?==?utf-8?B?cGRm?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment
Run Code Online (Sandbox Code Playgroud)

来自icloud:

Content-Transfer-Encoding: BASE64
Content-Type: APPLICATION/PDF;
    name="????-??????? =?utf-8?B?4oSWNDMyMSDQvtGC?= 4 ????.pdf"
Run Code Online (Sandbox Code Playgroud)

如何格式化icloud的名称?

UPD

如果我将消息从outlook(ms exchange)转发到icloud,则附件名称已成功解码.头:

Content-Transfer-Encoding: BASE64
Content-Disposition: ATTACHMENT;
    size=200702;
    modification-date="Mon, 04 Jul 2016 13:40:22 GMT";
    filename*=utf-8''%D0%A1%D1%87%D1%91%D1%82%2D%D0%B4%D0%BE%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%20%E2%84%964321%20%D0%BE%D1%82%204%20%D0%B8%D1%8E%D0%BB%D1%8F.pdf;
    creation-date="Mon, 04 Jul 2016 13:40:22 GMT"
Content-Type: …
Run Code Online (Sandbox Code Playgroud)

.net c# email encoding email-attachments

10
推荐指数
1
解决办法
1024
查看次数

如何使用Python将大文件附加到电子邮件-Gmail API

我正在尝试发送带有附件(最好是多个附件)的电子邮件,这些附件大于10 MB并且小于25 MB的总限制。我提到10 MB的原因是,这似乎是正常的附加文件方式停止起作用时得到的下限Error 10053

我在文档中已经读到,做到这一点的最佳方法是使用可恢复的上载方法,但我无法使其正常工作,也无法在Python中找到任何好的示例。关于此的大多数SO问题都只是链接回到没有Python示例的文档,否则它们的代码会导致其他错误。

我正在寻找Python中的解释,因为我想确保自己理解正确。

我浏览过的问题:

码:

import base64
import json
import os
from email import utils, encoders
from email.message import EmailMessage
from email.mime import application, multipart, text, base, image, audio
import mimetypes

from apiclient import errors
from googleapiclient import discovery, http
from google.oauth2 import service_account

def send_email(email_subject, email_body, email_sender='my_service_account@gmail.com', email_to='', email_cc='', email_bcc='', files=None):

    # Getting credentials
    with open(os.environ.get('SERVICE_KEY_PASSWORD')) as f:
        service_account_info …
Run Code Online (Sandbox Code Playgroud)

python mime email-attachments google-api-python-client gmail-api

10
推荐指数
1
解决办法
809
查看次数

更改电子邮件中自动附加文件的名称

我正在使用 Mailkit 库发送电子邮件。这是这样做的代码:

    public async Task SendAsync(IdentityMessage message)
    {
        if (message == null)
            return;

        LinkedResource inline = new LinkedResource(System.Web.Hosting.HostingEnvironment.MapPath($"~/Images/logo.png"))
        {
            ContentId = Guid.NewGuid().ToString(),
            ContentType = new ContentType("image/png")
            {
                Name = "logo.png"
            }
        };

        var htmlBody = message.Body.Replace("{CID:LOGO}", String.Format("cid:{0}", inline.ContentId));

        AlternateView avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
        avHtml.LinkedResources.Add(inline);

        using (MailMessage objMailMsg = new MailMessage())
        {
            objMailMsg.AlternateViews.Add(avHtml);
            objMailMsg.Body = htmlBody;
            objMailMsg.Subject = message.Subject;
            objMailMsg.BodyEncoding = Encoding.UTF8;

            Properties.Settings.Default.Reload();

            string fromEmail = Properties.Settings.Default.FromMail;
            string fromName = Properties.Settings.Default.FromName;
            string smtpPassword = Properties.Settings.Default.PwdSmtp;

            objMailMsg.From = new MailAddress(fromEmail, …
Run Code Online (Sandbox Code Playgroud)

c# smtpclient email-attachments mailkit

10
推荐指数
1
解决办法
120
查看次数