文件上传工作在localhost但不是godaddy服务器(dnn网站)

时间:2014-04-26 12:40:59

标签: c# email attachment smtpclient

我已经创建了一个模块,可以在本地发送带附件的电子邮件,但它在网络服务器(godaddy)上工作正常。我收到了这个错误。

发生严重错误。空路径名称不合法。

private void SendEmailNotification2()
{
    string to = "careers@domain.com";
    string from = "job@hotmail.com";
    string subject = "CV from Web Site";
    string body = "New CV from Web Site";

    using (MailMessage mm = newMailMessage(txtEmail.Text, "careers@domain.com"))
    {
        mm.Subject = "ssss";
        mm.Body = "baaa";
        if (FileUpload1.HasFile)
        {
            string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            mm.Attachments.Add(newAttachment(FileUpload1.PostedFile.InputStream, FileName));
        }

        mm.IsBodyHtml = false;
        SmtpClient smtp = newSmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { returntrue; };
        NetworkCredential NetworkCred = newNetworkCredential("job111@gmail.com", "Password");
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        // ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
    }
}

1 个答案:

答案 0 :(得分:1)

您是否可以在服务器上传文件? 默认情况下,GoDaddy服务器上的共享空间不允许文件上传(默认情况下,您的文件夹没有写入权限)

注意:我会将此作为对该问题的评论添加,但由于我现在无法发表评论,所以将其写在答案中。


很高兴帮忙!如果您觉得有帮助,请记得接受答案。