积极答复者
MailMessage 问题

问题
-
使用MailMessage中的Attachments
进行邮件附件的发送
有大小限制么?
这是附件部分的代码
Stream fileReader = new FileStream(fileInfo.FullName, FileMode.Open);
attachment = new Attachment(fileReader, fileInfo.Name);
_mailMessage.Attachments.Add(attachment);小文件1M以内的没有问题
大了以后就出现
发送邮件失败 索引超出界限的错误
Hero- 已移动 Jie Bao 2011年8月17日 10:27 (发件人:Windows Presentation Foundation)
答案
-
QQ邮箱的帮助信息里面应该有说明,它允许附件的大小。你可以看一下
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 HeroHua0509 2011年8月19日 7:28
全部回复
-
和WPF无关,不过我认为附件大小不是 MailMessage 决定的,是你的邮件服务器决定的。所以要check邮件服务器设置,而不是MailMessage的设置。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
恩,我也看了
SmtpClient这个类
好像也没有关于设置文件大小的地方
void SendMail()
{
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
_smtpClient.Host = GetMailNet(m_Address);//指定SMTP服务器
_smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
_smtpClient.Credentials = new System.Net.NetworkCredential(m_Address, m_Pwd);//用户名和密码
MailMessage _mailMessage = null;
try
{
_mailMessage = new MailMessage(m_Address, t_Address);
}
catch
{
MessageBox.Show("Sender or recipient address is not correct!");
return;
}
_mailMessage.Subject = mailTitle;//主题
_mailMessage.Body = mailContent;//内容
_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
_mailMessage.IsBodyHtml = true;//设置为HTML格式
_mailMessage.Priority = MailPriority.High;//优先级
Attachment attachment = null;
if (fileInfo != null)
{
//Stream fileReader = new FileStream(fileInfo.FullName, FileMode.Open);
//attachment = new Attachment(fileReader, fileInfo.Name);
attachment = new Attachment(fileInfo.FullName, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(fileInfo.FullName);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(fileInfo.FullName);
disposition.ReadDate = System.IO.File.GetLastAccessTime(fileInfo.FullName);
_mailMessage.Attachments.Add(attachment);
}
try
{
dis.BeginInvoke(new StopAngle(HideBorder), System.Windows.Threading.DispatcherPriority.Normal);
//border.Visibility = System.Windows.Visibility.Hidden;
_smtpClient.Send(_mailMessage);//发送
fileInfo = null;
attachment.Dispose();
}
catch
{
MessageBox.Show("Send failed!");
attachment.Dispose();
}}
这就是发送的过程了
Hero -
没错,你咨询下SMTP的配置,是否那边限制了?
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
QQ邮箱的帮助信息里面应该有说明,它允许附件的大小。你可以看一下
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 HeroHua0509 2011年8月19日 7:28