views:

147

answers:

3

I am trying to create a contact us page where visitor of the site can leave a message to site-admin.

say I m running this site www.example.com and i have an id [email protected] Now a new visitor visits my site and fills up the contact us form. He fills

FROM - [email protected] Subject- Query Message- My question....

I want to send this message as a mail to [email protected]

And on successfull sending of mail i want to send this user autogenerated mail as an acknowledgement.

What I need to do for this, My hosting server is GoDaddy

I am trying the following code.

    try
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress(txtEmailId.Text);
        mailMessage.To.Add(new MailAddress("[email protected]"));
        mailMessage.Subject = txtSubject.Text;
        mailMessage.Body = txtMessage.Text;
        mailMessage.IsBodyHtml = false;
        mailMessage.Priority = MailPriority.High;
        SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net");
        //sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPassword");
        sc.Send(mailMessage);
    }
    catch (Exception ex)
    {
        Label1.Text = "An Error has occured : "+ex.Message;
    }

This error occurs while trying to send mail.

Mailbox name not allowed. The server response was: sorry, your mail was administratively denied. (#5.7.1)

A: 

If you are using godaddy check this article out.

gmcalab
A: 

It is probably Serverfault.com question, any how

you need to check these options

Admin Home -> Configuration -> Email Options -> - E-Mail Transport Method = sendemail

reference 553 sorry, your mail was administratively denied. (#5.7.1)

Asad Butt
@Asad thr was some mistake in xplaining Q, Plz check the Edit
Shantanu Gupta
can you plz mark your editions under "EDIT", i cannot get you editions
Asad Butt
+1  A: 

It looks like from your code you are specifying that the mail message's From field is based on the email address the user fills in. The mail server mail be rejecting this and only allowing email from the domain name example.com or perhaps the server name itself. I've run into this before where your From field must be the original site domain...

If you want to have the ability for the form-mail recipient to directly reply, use the ReplyTo field rather than the from:

MailMessage mailMessage = new MailMessage();

//try using a domain address that matches your server and/or site.
//the email address itself may also have to exist depending on the mail server.
mailMessage.From = new MailAddress("[email protected]");

//set the replyto field
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);

//send the mail...   

Hope this might help...

EDIT:

After you've edited your question, the above is still relevant. It's very likely you cannot use a From address outside of your own site domain example.com. If you want to send two copies of the request (one to [email protected] and the other to the user as an acknowledgment), you simply need to add to the To property:

MailMessage mailMessage = new MailMessage();

//try using a domain address that matches your server and/or site.
//the email address itself may also have to exist depending on the mail server.
mailMessage.From = new MailAddress("[email protected]");

//add the contact email address to the To list
mailMessage.To.Add(new MailAddress("[email protected]"));

//add the user email address to the To list
mailMessage.To.Add(new MailAddress(txtEmailId.Text));

//set the replyto field
mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);

//send the mail...   

If you need to add a simple message for the user acknowledgment email you could also do:

try
{
    MailMessage mailMessage = new MailMessage();
    mailMessage.From = new MailAddress("[email protected]");
    mailMessage.To.Add(new MailAddress("[email protected]"));
    mailMessage.ReplyTo = new MailAddress(txtEmailId.Text);
    mailMessage.Subject = txtSubject.Text;
    mailMessage.Body = txtMessage.Text;
    mailMessage.IsBodyHtml = false;
    mailMessage.Priority = MailPriority.High;
    SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net");
    //sc.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPassword");

    //send to only the [email protected] first
    sc.Send(mailMessage);

    mailMessage.To.Clear();
    mailMessage.To.Add(new MailAddress(txtEmailId.Text));

    //add a simple message to the user at the beginning of the body
    mailMessage.Body = "Thank you for submitting your question. The following has been submitted to [email protected]: <br/><br/>" + mailMessage.Body;

    //send the acknowledgment message to the user
    sc.Send(mailMessage);

}
catch (Exception ex)
{
    Label1.Text = "An Error has occured : "+ex.Message;
}
KP
@KP u r right, But thr was some mistake in xplaining Q, Plz check the Edit
Shantanu Gupta