private void button1_Click(object sender, EventArgs e)
        {
    MailAddress from = new MailAddress("[email protected]", "Ben Miller");
    MailAddress to = new MailAddress("[email protected]", "Jane Clayton");
    MailMessage message = new MailMessage(from, to);
    // message.Subject = "Using the SmtpClient class.";
    message.Subject = "Using the SmtpClient class.";
    message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
    // Add a carbon copy recipient.
    MailAddress copy = new MailAddress("[email protected]");
    message.CC.Add(copy);
    Attachment attach=new Attachment(@"c:\a.txt");
    message.Attachments.Add(attach);
    SmtpClient client = new SmtpClient();
    // Include credentials if the server requires them.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    Console.WriteLine("Sending an e-mail message to {0} by using the SMTP host {1}.",
         to.Address, client.Host);
    client.Send(message);
}总是发送出错,我觉得是163的服务器我没设,但不知道应该怎么改才能成功。请高手指点……

解决方案 »

  1.   

    提示什么错误?发信的用户名叱?信箱的密码呢?没有这个两个你怎么发?还有那个POP3提供者[email protected]
      

  2.   

    System.Web.Mail.MailMessage mailmsg = new MailMessage(); ;
    try
    {
    //SMTP邮件服务器 SmtpMail.SmtpServer="smtp.mail.192.168.0.100";
    //发件人邮件帐号 mailmsg.To=txtto.Text.Trim();
    mailmsg.From=txtfrom.Text.Trim();
    if(txtcc.Text.Trim() !="")
    mailmsg.Cc=txtcc.Text.Trim();
    if(txtbcc.Text.Trim() !="")
    mailmsg.Bcc=txtbcc.Text.Trim();
    mailmsg.Body=txtcontent.Text.Trim();
    mailmsg.Subject=txttitle.Text.Trim();
    SmtpMail.Send(mailmsg);
    mailmsg=null;
    Response.Write("发送成功");
    }
    catch(Exception ex)
    {
    Response.Write("发送错误:" + ex.ToString()); }