爲什麼我不能發送xls,doc和其他文件 - 它可以用於jpg,txt和其他文件。通過gmail發送附件不能處理某些類型 - 爲什麼?
private void BuildAndSend(string pTo,string pCC,string pSubject,string pBody)
{
// building the mail
System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(pTo);
System.Net.Mail.MailAddress fromAddress = new System.Net.Mail.MailAddress("[email protected]");
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(fromAddress, toAddress);
mm.Subject = pSubject ;
mm.Body = pBody;
System.Net.Mail.MailAddress cc = new System.Net.Mail.MailAddress(pCC);
mm.CC.Add(cc);
addAttachments(mm);
mm.IsBodyHtml = true;
mm.BodyEncoding = System.Text.Encoding.UTF8;
//sending the mail
sendMail(mm);
}
private void addAttachments(System.Net.Mail.MailMessage mm)
{
string attachmentFile;
for (int i = 0; i < lstAttachments.Items.Count ; i++)
{
string fileFullName = pullDictionary[i];
attachmentFile = fileFullName;
System.Net.Mail.Attachment mailAttachment = new System.Net.Mail.Attachment(attachmentFile);
mm.Attachments.Add(mailAttachment);
}
}
private void sendMail(System.Net.Mail.MailMessage mm)
{
try
{
// loging in into sending user account
string smtpHost = "smtp.gmail.com";
string userName = "[email protected]";//sending Id
string password = "mypass";
System.Net.Mail.SmtpClient mClient = new System.Net.Mail.SmtpClient();
mClient.Port = 587;
mClient.EnableSsl = true;
mClient.UseDefaultCredentials = false;
mClient.Credentials = new NetworkCredential(userName, password);
mClient.Host = smtpHost;
mClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mClient.Send(mm);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
,如果你能告訴我另一種方式來發送這些文件,這將是偉大的,以及
什麼錯誤信息你好嗎?如果沒有,請圍繞Add()語句進行嘗試,然後更新您的帖子。 – 2010-07-09 22:02:49
你怎麼知道這些附件沒有被髮送?怎麼了?你有錯誤信息嗎?電子郵件是否在沒有附件的情況下發送? – Unicron 2010-07-09 22:03:36