| 发表于:2007-03-31 09:06:39 楼主 |
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(); } 这以上的代码是vs2005给出的发邮件附件的实例。 通过该实例,可以顺利的发邮件附件了,不过,这也只是可以发单个附件的。 我现在提问的是,在一封邮件中什么可以同时发多个附件? |
|
|
|
|