//邮件
MailMessage objMailMessage = new MailMessage();
// 创建一个附件对象
//MailAttachment objMailAttachment = new MailAttachment(@"C:\Documents and Settings\Administrator\桌面\自己收藏的电影片目.txt"); //发送邮件的附件 (此处改成你自己电脑上存在的路径,在此我就把这行注释掉,怕你忘了改,到时运行不了!
//objMailMessage.Attachments.Add(objMailAttachment);//将附件附加到邮件消息对象中
// 创建邮件消息
objMailMessage.From = "
[email protected]";//源邮件地址 (一定要把此邮箱改成你自己常用的新浪邮箱,我的密码不方便告诉你,如有不明白的地方可加我Q:86017974,或给我发信件:
[email protected])
objMailMessage.To = email;//";//目的邮件地址,也就是发给我啦!
objMailMessage.Subject = "注册成功!";//发送邮件的标题
objMailMessage.Body = "Dear '"+n+"' Thank you for choosing GizmospringYour password: '"+p+"'You can use this password to log in our Design room where you can see the progress of your project, send us messages, chat with our representatives.Thank you once again for your interest. Please contact us with any questions. Best regards, Gizmospring.com Customer Service";//发送邮件的内容
//接着利用sina的SMTP来发送邮件,需要使用Microsoft .NET Framework SDK v1.1和它以上的版本
//基本权限
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "
[email protected]"); //这里是我自己的账号,为了给你们测试,我暂时不改密码,如果测试失败时,此处一定要改成你自己的邮箱地址和更改下面的密码,以及上面的源邮箱地址,objMailMessage.From = "
[email protected]";如果不是用sina邮箱的话,服务器也得跟着改,就是这行代码也得改:SmtpMail.SmtpServer = "smtp.sina.com";
//密码
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //这是你用来发送邮件时用到的相应的邮箱密码,一定要记得改成你自己的邮箱密码.
//如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为: 554 : Client host rejected: Access denied
//SMTP地址
SmtpMail.SmtpServer = "smtp.163.com"; //我用的是新浪的服务器,这些代码如果用在网易163的服务器,就是把:"smtp.sina.com"改为:"smtp.163.com",上面把:objMailMessage.From = "
[email protected]";改成:objMailMessage.From = "
[email protected]";objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "
[email protected]");这里的"
[email protected]"改为:"
[email protected]"密码改为相应的密码,当然,这里得用你自己的邮箱,并且有一个问题就是,不能用刚申请的邮箱,不然会提示发送失败,要用有一定等级或积分的邮箱才能发送.
//开始发送邮件
SmtpMail.Send(objMailMessage);
//核心代码结束