前几天U盘丢了,心想如果能做一个小程序在U盘丢了的时候也能给我发送个邮件带上本机的地址就好了。
结合了Autorun.inf和这个程序就没问题了。
程序做出来了,现在的问题是,所有的机子都是在局域网,如果发送信息就会弹出失败信息。所以可以在发送前尝试是否网络通畅,否则不发之类的验证,
但是后来懒得做了,心想人家捡到U盘,也差不多就格式化了,做了也没用。不过倒是涉及到了一些代码。所以存下来备份。

private void sengmill_net()
  
{//.net smtp类进行邮件发送,支持认证,附件添加;
   System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
   mailmsg.From 
= this.tb_from.Text.Trim();
   mailmsg.To   
= this.tb_to.Text.Trim();
   mailmsg.Body 
= this.tb_mailBody.Text.Trim();
   mailmsg.Subject 
= "test mail from hz";
   
/* 附件的粘贴, ^_^,笨了点;
   if(this.att1.Value.ToString().Trim()!=string.Empty)
    mailmsg.Attachments.Add(new System.Web.Mail.MailAttachment(this.att1.Value.ToString().Trim()));
   if(this.att2.Value.ToString().Trim()!=string.Empty)
    mailmsg.Attachments.Add(new System.Web.Mail.MailAttachment(this.att2.Value.ToString().Trim()));
   if(this.att3.Value.ToString().Trim()!=string.Empty)
    mailmsg.Attachments.Add(new System.Web.Mail.MailAttachment(this.att3.Value.ToString().Trim()));
   
*/

   mailmsg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1");
   
//是否需要验证,一般是要的    
   mailmsg.Fields.Add 
    (
"http://schemas.microsoft.com/cdo/configuration/sendusername""gallon_han"); 
   
//自己邮箱的用户名    
   mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword""218500");
   
//自己邮箱的密码 
   System.Web.Mail.SmtpMail.SmtpServer = this.tb_smtpserver.Text.Trim();
   System.Web.Mail.SmtpMail.Send(mailmsg);
  }



 

AutoRun.inf


[AutoRun]
open=xx.exe
shell\open=打开(&O)
shell\open\Command=SendMailForUdisk.exe
shell\open\Default=1
shell\explore=资源管理器(&X)
shell\explore\Command=SendMailForUdisk.exe
open=\