1

Thanks for looking at my question.

I am trying to figure out attachments for OpenNetCF.Net.Mail. Here is the code for my SendMail function:

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();
    }
}

It is supposed to be a matter of tweaking it in the following way to allow attachments:

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

The problem is that I cannot figure out how to get the attachment to add. The lines above should be it with something else in the middle where I actually tell it what file I would like to attach. Any help on this matter will be greatly appreciated.

Thanks again!

jnsohnumr
  • 159
  • 1
  • 2
  • 13
  • Do you mean you want multiple attachments or something of that sort? – Mamta D Aug 23 '11 at 18:00
  • Only a single attachment, a zip file – jnsohnumr Aug 23 '11 at 18:19
  • What code are you using to attach and what error are you getting? Or is it that the Attachment class doesn't have the API required to add files to it? – Quibblesome Aug 23 '11 at 19:19
  • It seems the attachment class does not have everything i need. I have not been able to find out how to actually indicate the filename and path of what I would like to attach. – jnsohnumr Aug 23 '11 at 19:38
  • I tried using the PocketOutlook attachment class and casting, but there was no conversion available to make that work. – jnsohnumr Aug 23 '11 at 19:39

2 Answers2

0

They have AttachmentBase which can be used to construct a email attachment. However, we cannot add the instance of AttachmentBase to the attachments of email message.

I think the Attachment class should inherit from AttachmentBase. I think this maybe a defect.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Jessie
  • 1
  • The primary "defect" is that we never implemented attachments. If you look at the source code, it's just all stubbed out. I've thought about implementing it - several times in fact - but the reality is that I can still count on one hand the number of requests for it I've gotten and I always have so much more to do. Maybe for the next version of the CF I'll revisit it. – ctacke Jun 22 '12 at 02:43
0

As per this MSDN documentation, you can specify the filename of the attachment as a parameter. Thus, you can give the fullpath as the string parameter.

Mamta D
  • 6,310
  • 3
  • 27
  • 41
  • Yes, I was able to do that, but the problem is that I cannot cast the PocketOutlookAttachment as an opennetcf.net.mail attachment, which is what I actually need. – jnsohnumr Aug 24 '11 at 16:06
  • @jnsohnumr, an old thread on the community forum showed that to be a bug. And looks like they never rectified that bug. See here: http://community.opennetcf.com/forums/t/11325.aspx – Mamta D Aug 24 '11 at 16:55
  • Thanks ended up using a commercial product linked somewhere else: http://www.enterprisedt.com/products/edtftpnetcompact/purchase.html – jnsohnumr Aug 24 '11 at 18:33