M.Carreira
M.Carreira

Reputation: 87

Error when changing the smtp host in asp.net

5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.

I have an ASP.NET web application that has a contact page with a form. It was going to well until I changed the host. For example, if I change the host to smtp.live.com instead of smtp.gmail.com I got the error that is above. My question is, if my host is from my gmail account, it works fine but if I change it, it doesn't work. I've already searched other questions but they are different from mine and can't find any suitable answer on Google.

My code is the following:

public partial class WebForm2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage("[email protected]", "[email protected]");
        mm.Subject = TextBox1.Text;
        mm.Body = "Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + TextBox2.Text;

        if (FileUpload1.HasFile)
        {
            string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
        }

        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        //smtp.Host = "smtp.gmail.com";
        smtp.Host = "smtp.live.com";
        smtp.EnableSsl = true;
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
        NetworkCred.UserName = "[email protected]";
        NetworkCred.Password = "xxxxxxxx";
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        lblMessage.Text = "Email Sent SucessFully.";
    }
}

Upvotes: 3

Views: 439

Answers (1)

M.Carreira
M.Carreira

Reputation: 87

ANSWER: Through this question -> PHPMailer .Exception:SendAsDeniedException.MapiExceptionSendAsDenied , I changed the "[email protected]" to another mail of mine and worked.

Upvotes: 1

Related Questions