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