小编sim*_*sim的帖子

Django EmailMultiAlternatives以HTML中的Embadded Image

我正在尝试使用HTML和embadded图像发送电子邮件.电子邮件发送工作正常,它还将图像附加到电子邮件中,但它没有以HTML格式显示图像(内联).我在视图中使用了Content:ID,在模板中使用了cid但没有成功:(.我探索了很多表单并应用了解决方案,但是徒劳无助请帮忙!这是我的代码:

html_content = render_to_string('newsletters/newsletter_template.html', vars)
text_content = strip_tags(html_content) 

to = 'myemail@gmail.com'


msg = EmailMultiAlternatives(self.subject, text_content, settings.STAFF_FROM_EMAIL, [to])
msg.attach_alternative(html_content, "text/html")

image_file = open('../media/images/banner_admin.gif', 'rb')
msg_image = MIMEImage(image_file.read())
image_file.close()

msg_image.add_header('Content-ID', '<image1>')
msg.attach(msg_image)

msg.send()
Run Code Online (Sandbox Code Playgroud)

模板文件:

<div style="border:2px solid #CCCCCC; width:900px; font-size:10px; padding:5px;">
    <div style="margin-bottom: 10px;"><img src="cid:image1" /></div>
    <div style="">{{body|linebreaks}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)

如果我在这里遗漏了什么,请告诉我...

python email django

5
推荐指数
1
解决办法
1754
查看次数

HttpWebRequest的.远程服务器返回错误:(500)内部服务器错误

我需要在C#中使用HttpWebRequest提供帮助.下面的代码行适用于本地IIS,但是当我上传到远程服务器时,它开始给我"远程服务器返回错误:(500)内部服务器错误.".我用GET和POST方法尝试了很多变化,但无法弄清楚问题是什么.请查看下面的代码,让我知道这有什么问题.

try
{
    string postData = "applicaitonid=abc&deviceid=xyz";
    string uri = System.Configuration.ConfigurationManager.AppSettings.Get("baseUrl") + System.Configuration.ConfigurationManager.AppSettings.Get("ABApiPath") + "ConfirmAppBinding/?" + postData;

    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)WebRequest.Create(uri);
    request.Method = "POST"; // Set type Post
    //request.Method = "GET";
    request.UserAgent = Request.UserAgent.ToString();
    request.ContentType = @"application/json";
    request.MediaType = "application/json";
    request.Accept = "application/json";
    request.KeepAlive = false;
    request.ProtocolVersion = HttpVersion.Version11;
    //byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(postData);
    request.Timeout = 500000;             //Increase timeout for testing

    Stream reqstr = request.GetRequestStream();
    //reqstr.Write(buffer, 0, buffer.Length);
    reqstr.Close();

    // Read Response
    var httpResponse = request.GetResponse();
    using (var streamReader = new …
Run Code Online (Sandbox Code Playgroud)

c# httpwebrequest internal-server-error

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