返回首页

你好
我错误无效的邮件附件'1 XML的附着线。
感谢


 

using System;

using System.IO;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Mail;

 



public partial class Web_careers : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

       // clearfields();

    }

    public void clearfields()

    {

        txtName.Text = "";

        txtEmail.Text = "";

        txtcomment.Text = "";

        txtapply.Text = "";

    }

 

    protected void imgsubmit_Click(object sender, ImageClickEventArgs e)

    {

      

        string sHost = System.Configuration.ConfigurationManager.AppSettings["Host"].ToString();

        string sUserName = System.Configuration.ConfigurationManager.AppSettings["AutorptUser"].ToString();

        string sPassword = System.Configuration.ConfigurationManager.AppSettings["AutorptPassword"].ToString();

        string sFromEmail = System.Configuration.ConfigurationManager.AppSettings["AutorptFromEmail"].ToString();

        int    nPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"].ToString());

        bool fSSL = true;

 

        string MessageBody = "";

        string result = "";

        try

        {

            System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();

            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;

            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;

 

            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();

            if (fSSL)

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";

 

            if (sUserName.Length == 0)

            {

                //Ingen auth 

            }

            else

            {

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;

                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;

            }

           

            string file = fuResume.PostedFile.FileName;

            MessageBody = File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("../web/careers.txt"));

 

            MessageBody = MessageBody.Replace("$name$", txtName.Text);

            MessageBody = MessageBody.Replace("$email$", txtEmail.Text);

            MessageBody = MessageBody.Replace("$ApplyFor$", txtapply.Text);

            MessageBody = MessageBody.Replace("$coments$", txtcomment.Text);

            MessageBody = MessageBody.Replace("$Attachment$", file);

           

 

           

            System.Web.Mail.MailAttachment attachment;

            attachment = new System.Web.Mail.MailAttachment(file);

 

            Mail.To = txtEmail.Text;

            Mail.From = sFromEmail;

            Mail.Subject = "Enquiry";

            Mail.BodyFormat = System.Web.Mail.MailFormat.Html;

            Mail.Body = MessageBody;

 

            Mail.Attachments.Add(attachment);

 



            System.Web.Mail.SmtpMail.SmtpServer = sHost;

            System.Web.Mail.SmtpMail.Send(Mail);

            result = "MailSuccess";

        }

        catch (Exception ex)

        {

            result = ex.Message;

        }

    }

}

回答

评论会员: 时间:2