我也不会,要不用第三方控件吧,CDO,JMAIL什么的

解决方案 »

  1.   

    这里有个vb的,你参考:
    VB.NEt自动发邮件
    我写过一段:
    '=================================================
    '类名:SendMail
    '名称空间:SendMail.SendMail
    '功能:用于发送邮件
    '编写人:NoReady
    '编写日期:2003-10-13
    '最后修改人:
    '最后修改日期:
    '=================================================Imports System.serviceprocess
    Imports System.Web.mailPublic Class SendMail    '-------------------参数说明---------------------
        '先检查源邮件地址和目标邮件地址及附件是否有效
        'From:源邮件地址
        'To:目标邮件地址
        'Title:邮件标题
        'Message:邮件内容
        'Attach:附件
        'Priority:邮件优先级
        '------------------------------------------------    Public Function SendMail(ByVal From As String, ByVal SendTo As String, _
                            ByVal Title As String, ByVal Content As String, _
                            ByVal Attach As String, ByVal Priority As MailPriority) As Boolean        '邮件信息
            Dim msgMail As New MailMessage        Try            '检查邮件地址及附件是否有效
                If InStr(From, "@", CompareMethod.Text) <= 0 Or From.Length <= InStr(From, "@", CompareMethod.Text) Then
                    Throw New Exception("源邮件地址错误!")
                End If            If InStr(SendTo, "@", CompareMethod.Text) <= 0 Or SendTo.Length <= InStr(SendTo, "@", CompareMethod.Text) Then
                    Throw New Exception("目标邮件地址错误!")
                End If            '附件
                If Attach.Trim <> "" Then
                    If Dir(Attach.Trim) = "" Then
                        Throw New Exception("不存在附件中指定的文件!")
                    Else
                        msgMail.Attachments.Add(New MailAttachment(Attach))
                    End If
                End If
                '配置邮件信息
                With msgMail
                    .From = From
                    .To = SendTo
                    .Subject = Title
                    .Body = Content
                    .Priority = Priority
                End With
                '发送邮件
                SmtpMail.Send(msgMail)            Return True        Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try    End Function    'Function SendMailEnd Class   'class SendMail
      

  2.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    MailMessage aMail = new MailMessage();
    aMail.To  = TextBox1.Text;
    aMail.From = TextBox2.Text;
    aMail.Subject = TextBox3.Text;
    aMail.Body = TextBox5.Text;
    if (File1.PostedFile.FileName != "")
    {
    string fname = File1.PostedFile.FileName;
    fname = fname.Substring(fname.LastIndexOf(@"\"));
    fname = Server.MapPath(fname);
    File1.PostedFile.SaveAs(fname);//File1是一个文件上传控件。
    aMail.Attachments.Add(new MailAttachment(fname));
    }

    try
    {
    SmtpMail.Send(aMail);
    Label6.Text = "success!";
    }
    catch (Exception ex)
    {
    Label6.Text = ex.ToString();
    }
    }
      

  3.   

    jie115说得对你的错误显示,明显是因为附件路径不对,或者说找不到你必须将它上传到你的服务器上这样才不会出现上述的问题
      

  4.   

    使用jmail控件吧。比较不错。方便。
      

  5.   

    谢谢,我明白了是路径的问题,谢谢!
    谢谢;cdo(cdo),jie115(守望红木),lansluo(最后一个女巫)