MailMessage.Attachmentsとは? わかりやすく解説

MailMessage.Attachments プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

この電子メール メッセージ添付されるデータ格納するために使用する添付データコレクション取得します

名前空間: System.Net.Mail
アセンブリ: System (system.dll 内)
構文構文

Public ReadOnly Property
 Attachments As AttachmentCollection
Dim instance As MailMessage
Dim value As AttachmentCollection

value = instance.Attachments
public AttachmentCollection Attachments { get;
 }
public:
property AttachmentCollection^ Attachments {
    AttachmentCollection^ get ();
}
/** @property */
public AttachmentCollection get_Attachments ()
public function get Attachments
 () : AttachmentCollection

プロパティ
書き込み可能な AttachmentCollection。

解説解説
使用例使用例

添付データ含んだ電子メール メッセージ作成および送信を行うコード例次に示します

public static void CreateMessageWithAttachment(string
 server)
{
    // Specify the file to be attached and sent.
    // This example assumes that a file named Data.xls exists in the
    // current working directory.
    string file = "data.xls";
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "Quarterly data report.",
       "See the attached spreadsheet.");

    // Create  the file attachment for this e-mail message.
    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this e-mail message.
    message.Attachments.Add(data);
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    // Add credentials if the SMTP server requires them.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    client.Send(message);
    // Display the values in the ContentDisposition for the attachment.
    ContentDisposition cd = data.ContentDisposition;
    Console.WriteLine("Content disposition");
    Console.WriteLine(cd.ToString());
    Console.WriteLine("File {0}", cd.FileName);
    Console.WriteLine("Size {0}", cd.Size);
    Console.WriteLine("Creation {0}", cd.CreationDate);
    Console.WriteLine("Modification {0}", cd.ModificationDate);
    Console.WriteLine("Read {0}", cd.ReadDate);
    Console.WriteLine("Inline {0}", cd.Inline);
    Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
    foreach (DictionaryEntry d in cd.Parameters)
    {
        Console.WriteLine("{0} = {1}", d.Key, d.Value);
    }
    data.Dispose();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MailMessage クラス
MailMessage メンバ
System.Net.Mail 名前空間

MailMessage.Attachments プロパティ

メッセージと共に送信される添付ファイルコレクション指定します推奨する代替 : System.Net.Mail

名前空間: System.Web.Mail
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public ReadOnly Property
 Attachments As IList
Dim instance As MailMessage
Dim value As IList

value = instance.Attachments
public IList Attachments { get; }
public:
property IList^ Attachments {
    IList^ get ();
}
/** @property */
public IList get_Attachments ()
public function get Attachments
 () : IList

プロパティ
MailAttachment オブジェクトの IList コレクション

解説解説

Message.Attachments.Add(MyMailMessage)呼び出しによって、メール メッセージ新し添付ファイル追加されます。SmtpMail の使用法例については、Sendトピック参照してください

使用例使用例
Dim MyMessage As MailMessage = new
 MailMessage()
MyMessage.Attachments.Add(New MailAttachment(fileName1))
MyMessage.Attachments.Add(New MailAttachment(fileName2, MailEncoding.UUEncode))
MailMessage MyMessage = new MailMessage();
MyMessage.Attachments.Add(new MailAttachment(fileName1));
MyMessage.Attachments.Add(new MailAttachment(fileName2, MailEncoding.UUEncode));
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MailMessage クラス
MailMessage メンバ
System.Web.Mail 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MailMessage.Attachments」の関連用語

MailMessage.Attachmentsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MailMessage.Attachmentsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS