C#调用邮件发送


        //MailMessage mail = new MailMessage();
        //mail.From = this.from.Text.Trim();
     
    protected void Button1_Click(object sender, EventArgs e)
    {
        //MailMessage mail = new MailMessage();
        //mail.From = this.from.Text.Trim();
        //mail.To = this.to.Text.Trim();
        //mail.Subject = this.subject.Text.Trim();
        //mail.Body = this.content.Text.Trim();
        ////SmtpMail.SmtpServer = "tom.com";
        //mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
        //mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.username.Text.Trim());
        //mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.userpassword.Text.Trim());
        //SmtpMail.Send(mail);//发送
        //msg.Text = "发送成功";

        MailAddress from=new MailAddress(this.sendfrom.Text.Trim());
        MailAddress to=new MailAddress(this.sendto.Text.Trim());
        MailMessage mailobj=new MailMessage(from,to);
        mailobj.Subject=subjectform.Text.Trim();
        mailobj.Body=contentfrom.Text.Trim();
        mailobj.IsBodyHtml = true;
        mailobj.Priority = MailPriority.High;
        //if (File1.Value.ToString() != "")
            //{
            //    // 为邮件添加附件
            //    Attachment addFile = new Attachment(File1.Value.ToString(), MediaTypeNames.Application.Octet);
            //    mailObj.Attachments.Add(addFile);
            //} 
           // SmtpMail.SmtpServer = "tom.com"; 
        SmtpClient sc = new SmtpClient();
        sc.Host = "192.168.16.229";
        sc.Credentials = new NetworkCredential(this.username.Text.Trim(),this.userpassword.Text.Trim());
        sc.Send(mailobj);
        msg.Text="发送成功";

    }

你可能感兴趣的:(C++,c,Microsoft,C#)