您的位置:程序门 -> .net技术 -> c#



关于什么发多个邮件附件的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于什么发多个邮件附件的问题[已结贴,结贴人:luyangph]
发表于: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给出的发邮件附件的实例。
通过该实例,可以顺利的发邮件附件了,不过,这也只是可以发单个附件的。


我现在提问的是,在一封邮件中什么可以同时发多个附件?


发表于:2007-03-31 15:36:411楼 得分:20
up
发表于:2007-04-25 10:27:192楼 得分:0


关于这个问题,
我自己找到了答案,
现在大概意思一下
mail.attachments.add(new   attachment( "c:\\temp\\example.txt "));
mail.attachments.add(new   attachment( "c:\\temp\\example2.txt "));
mail.attachments.add(new   attachment( "c:\\temp\\example3.txt "));

更多详情
可以查看此网页
http://www.systemnetmail.com/

就此结贴吧




快速检索

最新资讯
热门点击