公司的领料系统填写申请领料单后,
希望系统能自动发送一份邮件给上级审核,
(公司的网络与外网是断开的,但公司内部有内部的邮件系统)
请教如何实现内网邮件发送我在网上找了一段代码是发送外网的,已經测试发送邮件成功,现在我要改成发送内网地址的邮件,请教如何修改,谢谢!
发送外网的代码如下:
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                format.Items.Add(new ListItem("文本", "0"));
                format.Items.Add(new ListItem("HTML", "1"));
                format.Items[0].Selected = true;                fromMail.Text = "要用內網的地址"; //发送方邮件
                fromMail.Enabled = false;
            }
        }        private bool SendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
        {
            try
            {
        
                MailMessage myMail = new MailMessage();
                myMail.From = fromMail;
                myMail.To = fromMail;
                myMail.Cc = ccMail;
                myMail.Bcc = bccMail;
                myMail.Subject = subject;
                myMail.Body = body;
                myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;                //附件
                string ServerFileName = "";
                if (this.upfile.PostedFile.ContentLength != 0)
                {
                    string upFileName = this.upfile.PostedFile.FileName;
                    string[] strTemp = upFileName.Split('.');
                    string upFileExp = strTemp[strTemp.Length - 1].ToString();
                    ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                    this.upfile.PostedFile.SaveAs(ServerFileName);
                    myMail.Attachments.Add(new MailAttachment(ServerFileName));
                }
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "JACKY"); //发送方邮件帐户
                myMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "think614"); //发送方邮件密码                SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                SmtpMail.Send(myMail);                return true;
            }
            catch
            {
                return false;
            }
        }        protected void send_Click(object obj, EventArgs e)
        {
            bool flag = SendMail(fromMail.Text, toMail.Text, ccMail.Text, bccMail.Text, subject.Text, body.Text, format.SelectedValue);
            if (flag == true)
            {
                Response.Write("<script>alert('发送成功!');</script>");
            }
            else
            {
                Response.Write("<script>alert('发送失败!');</script>");
            }
        }

解决方案 »

  1.   

     SmtpMail.SmtpServer=内网smtp服务器地址
      

  2.   

    做如下變更,測試還是通不成功,再請幫忙,謝謝 
    public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    format.Items.Add(new ListItem("文本", "0"));
                    format.Items.Add(new ListItem("HTML", "1"));
                    format.Items[0].Selected = true;                fromMail.Text = "[email protected]"; //发送方邮件
                    fromMail.Enabled = false;
                }
            }        private bool SendMail(string fromMail, string toMail, string ccMail, string bccMail, string subject, string body, string sendMode)
            {
                try
                {
                    MailMessage myMail = new MailMessage();
                    myMail.From = fromMail;
                    myMail.To = fromMail;
                    myMail.Cc = ccMail;
                    myMail.Bcc = bccMail;
                    myMail.Subject = subject;
                    myMail.Body = body;
                    myMail.BodyFormat = sendMode == "0" ? MailFormat.Text : MailFormat.Html;                //附件
                    string ServerFileName = "";
                    if (this.upfile.PostedFile.ContentLength != 0)
                    {
                        string upFileName = this.upfile.PostedFile.FileName;
                        string[] strTemp = upFileName.Split('.');
                        string upFileExp = strTemp[strTemp.Length - 1].ToString();
                        ServerFileName = Server.MapPath(DateTime.Now.ToString("yyyyMMddhhmmss") + "." + upFileExp);
                        this.upfile.PostedFile.SaveAs(ServerFileName);
                        myMail.Attachments.Add(new MailAttachment(ServerFileName));
                    }
                    myMail.Fields.Add("192.168.1.16", 1);
                    myMail.Fields.Add("http://192.168.1.16", "212060"); //发送方邮件帐户
                    myMail.Fields.Add("http://192.168.1.16", "think614"); //发送方邮件密码

                    SmtpMail.SmtpServer = "smtp." + fromMail.Substring(fromMail.IndexOf("@") + 1);
                    SmtpMail.Send(myMail);                return true;
                }
                catch
                {
                    return false;
                }
            }        protected void send_Click(object obj, EventArgs e)
            {
                bool flag = SendMail(fromMail.Text, toMail.Text, ccMail.Text, bccMail.Text, subject.Text, body.Text, format.SelectedValue);
                if (flag == true)
                {
                    Response.Write("<script>alert('发送成功!');</script>");
                }
                else
                {
                    Response.Write("<script>alert('发送失败!');</script>");
                }
            }
        }