您的位置:首页 > 其它

使用WebProxy发送邮件

2007-08-20 16:57 232 查看

System.Net.WebProxy proxy = new System.Net.WebProxy("itgproxy.redmond.corp.microsoft.com:80");


            proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;


            System.Net.GlobalProxySelection.Select = proxy;


            MailMessage m = new MailMessage();


            m.From = tbFrom.Text;


            m.To = tbTo.Text;


            m.Subject = tbSubject.Text;


            m.Body = tbBody.Text;


            //优先级


            switch(ddlp.SelectedIndex)




            ...{


                case 0:


                    m.Priority = MailPriority.High;


                    break;


                case 1:


                    m.Priority = MailPriority.Low;


                    break;


                default:


                    m.Priority = MailPriority.Normal;


                    break;


            }


            //格式


            if(ddlp.SelectedIndex==0)


                m.BodyFormat = MailFormat.Text;


            else


                m.BodyFormat = MailFormat.Html;


            //以下设置服务器


            if(tbServer.Text!="")




            ...{


                


                //以下代码适用于Framework1.1以上版本。


                //SmtpMail.SmtpServer = tbServer.Text;


//                m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",


//                    "1");    //basic authentication


//                m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",


//                    tbUserName.Text); //set your username here


//                m.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",


//                    tbPass.Text);    //set your password here


            }


            //以下处理附件 


            string strFileName = FileSelect.PostedFile.FileName;


            if(strFileName!="")


                m.Attachments.Add(new MailAttachment(strFileName));


            SmtpMail.Send(m);

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string 服务器