1

謝謝你看我的問題。opennetcf.net.mail附件幫助

我想弄清楚OpenNetCF.Net.Mail的附件。這裏是我的SendMail函數的代碼:

public static void SendMessage(string subject, 
    string messageBody, 
    string fromAddress, 
    string toAddress, 
    string ccAddress) 
{ 
    MailMessage message = new MailMessage(); 
    SmtpClient client = new SmtpClient(); 

    MailAddress address = new MailAddress(fromAddress); 

    // Set the sender's address 
    message.From = address; 

    // Allow multiple "To" addresses to be separated by a semi-colon 
    if (toAddress.Trim().Length > 0) 
    { 
     foreach (string addr in toAddress.Split(';')) 
     { 
      message.To.Add(new MailAddress(addr)); 
     } 
    } 

    // Allow multiple "Cc" addresses to be separated by a semi-colon 
    if (ccAddress.Trim().Length > 0) 
    { 
     foreach (string addr in ccAddress.Split(';')) 
     { 
      message.CC.Add(new MailAddress(addr)); 
     } 
    } 

    // Set the subject and message body text 
    message.Subject = subject; 
    message.Body = messageBody; 

    // TODO: *** Modify for your SMTP server *** 
    // Set the SMTP server to be used to send the message 
    client.Host = "smtp.dscarwash.com"; 
    string domain = "dscarwash.com"; 
    client.Credentials = new SmtpCredential("mailuser", "dscarwash10", domain); 

    // Send the e-mail message 
    try 
    { 
     client.Send(message); 
    } 
    catch (Exception e) 
    { 
     string data = e.ToString(); 
    } 
} 

它應該是通過以下方式調整它允許附件的問題:

Attachment myAttachment = new Attachment(); 
message.Attachments.Add(myAttachment); 

的問題是,我無法弄清楚如何獲取附件添加。上面的代碼應該是中間的其他東西,我實際上告訴它我要附加的文件。任何有關此事的幫助將不勝感激。

再次感謝!

+0

你的意思是你想要多個附件或類似的東西? –

+0

只有一個附件,一個zip文件 – jnsohnumr

+0

您使用什麼代碼來附加以及出現什麼錯誤?還是說Attachment類沒有向其中添加文件所需的API? – Quibblesome

回答

0

按照此MSDN documentation,您可以指定附件的文件名作爲參數。因此,您可以將完整路徑作爲字符串參數。

+0

是的,我能夠做到這一點,但問題是我無法將PocketOutlookAttachment作爲opennetcf.net.mail附件投放,這正是我真正需要的。 – jnsohnumr

+0

@jnsohnumr,社區論壇上的一箇舊帖子顯示出這是一個bug。看起來他們從來沒有糾正過這個錯誤。看到這裏:http://community.opennetcf.com/forums/t/11325.aspx –

+0

謝謝結束了使用鏈接到其他地方的商業產品:http://www.enterprisedt.com/products/edtftpnetcompact/purchase.html – jnsohnumr

0

他們有AttachmentBase可用於構建電子郵件附件。但是,我們無法將AttachmentBase的實例添加到電子郵件附件中。我想Attachment類應該從AttachmentBase繼承。我認爲這可能是一個缺陷。

+0

主要的「缺陷」是我們從未實施過附件。如果你看看源代碼,它只是被全部剔除了。我曾經想過實施它 - 事實上有好幾次 - 但事實是,我仍然可以依靠我得到的要求數量,而且我總是有很多事情要做。也許對於CF的下一個版本,我會重新審視它。 – ctacke