opennetcf.net.mail 附件帮助

发布于 2024-11-30 19:11:31 字数 1690 浏览 2 评论 0原文

感谢您查看我的问题。

我正在尝试找出 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);

问题是我无法弄清楚如何添加附件。上面的行应该是中间有其他东西,我实际上告诉它我想附加什么文件。任何有关此事的帮助将不胜感激。

再次感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无言温柔 2024-12-07 19:11:31

根据此 MSDN 文档,您可以指定附件的文件名作为参数。因此,您可以将完整路径作为字符串参数。

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.

跨年 2024-12-07 19:11:31

他们有 AttachmentBase 可用于构建电子邮件附件。但是,我们无法将 AttachmentBase 实例添加到电子邮件的附件中。

我认为 Attachment 类应该继承于 AttachmentBase。我想这可能是一个缺陷。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文