1

私の質問を見てくれてありがとう。

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

問題は、添付ファイルを追加する方法がわからないことです。上記の行は、実際に添付するファイルを指定する中央に何か他のものがあるはずです。この問題に関する助けをいただければ幸いです。

再度、感謝します!

4

2 に答える 2

0

このMSDNドキュメントに従って、添付ファイルのファイル名をパラメータとして指定できます。したがって、文字列パラメータとしてフルパスを指定できます。

于 2011-08-24T04:03:41.170 に答える
0

それらはAttachmentBase、電子メールの添付ファイルを作成するために使用できるものを持っています。AttachmentBaseただし、メールメッセージの添付ファイルにのインスタンスを追加することはできません。

Attachmentクラスはから継承する必要があると思いますAttachmentBase。これはおそらく欠陥だと思います。

于 2012-06-22T02:06:42.247 に答える