当前位置:编程学习 > C#/ASP.NET >>

C#smtp服务器发送邮件

通过smtp服务器发送邮件:
//txtFrom.text是发件人邮件地址,txtGet.Text是收件人邮件地址
                    MailMessage Mail = new MailMessage(this.txtFrom.Text, this.txtGet.Text);
                   
                    Mail.Subject = this.txtSubject.Text.Trim().ToString();
                    Mail.Body = this.richTextBox1.Text.Trim().ToString();
                    SmtpClient Client = new SmtpClient("smtp.126.com",25);    //实例一个SmtpClient类
                    //txtusername是发件人邮箱的帐号,txtpwd是邮箱的密码
                    Client.Credentials = new System.Net.NetworkCredential(txtusername.Text,txtpwd.Text);
                    //Client.Host = "smtp.126.com";
                    //附件
                    if (txtAttach.Text.Length > 0)
                    {
                       //添加附件
                        Mail.Attachments.Add(new Attachment(txtAttach.Text, MediaTypeNames.Application.Octet));
                    }
                      //发送邮件
                    Client.Send(Mail);
 
程序的界面设计如下:
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,