无法发送带有附件的电子邮件

编程入门 行业动态 更新时间:2024-10-28 21:28:29
本文介绍了无法发送带有附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的问题是,我试图利用管理员网站上的电子邮件发送任务。

My issue is this that I am trying to make use of email sending task at my website for the admin individual.

当他从可用列表中选择电子邮件ID时数据,添加附件并发送电子邮件,但用户从未收到过。但是,如果他使用的是简单邮件,即。

When he selects the email ids from the available data, adds an attachment and sends the email, it was never received by user. However, if he is using simple mailing ie. without any attachment, user receives it.

您能帮忙吗?

我的编码如下:-

public partial class SahibAdmin_emailNewsletter : System.Web.UI.Page { // ... private void SendNewsletter(string emailId) { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); message.To = emailId; message.From = "info@sahibimports"; message.Subject = "Please See: Newsletter from Sahib imports"; message.BodyFormat = System.Web.Mail.MailFormat.Text; message.Body = txtBody.Text.ToString(); if (msgUpload.HasFile) { //string strFileName = msgUpload.FileName; //msgUpload.PostedFile.SaveAs(Server.MapPath(strFileName)); //System.Web.Mail.MailAttachment attach = // new System.Web.Mail.MailAttachment(Server.MapPath(strFileName)); //message.Attachments.Add(attach); message.Attachments.Add(new Attachment( FileUpload.PostedFile.InputStream, FileUpload.FileName)); } System.Web.Mail.SmtpMail.Send(message); Response.Flush(); }

推荐答案

msdn.microsoft/en-us/library/6sdktyws.aspx 您的附件构造函数正在尝试使用第二个参数设置ContentType,但是您要传递文件名,确定正确吗?

According to msdn.microsoft/en-us/library/6sdktyws.aspx your Attachment constructor is trying to set the ContentType with the second parameter but you're passing in a filename, are you sure that is correct?

您可能应该将该部分更改为以下内容:

You should probably change that part to something like:

ContentType contentType = // create suitable type here based on your file format Attachment attachment = new Attachment( FileUpload.PostedFile.InputStream, contentType ); attachment.ContentDisposition.FileName = FileUpload.FileName; message.Attachments.Add(attachment);

更多推荐

无法发送带有附件的电子邮件

本文发布于:2023-05-27 19:34:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/300606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!