开发者

Receiving Emails on Hosting Domain Email Id from any user visiting to site

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 contact@example.com Now a new visitor visits my site and fills up the contact us form. He fills

FROM - abc@yahoo.com Subject- Query Message- My question....

I want to send this message as a mail to contact@example.com

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("contact@example.com"));
        mailMessage.Subject = txtSubject.Text;
        mailMessage.Body = txtMessage.Text;
  开发者_Python百科      mailMessage.IsBodyHtml = false;
        mailMessage.Priority = MailPriority.High;
        SmtpClient sc = new SmtpClient("relay-hosting.secureserver.net");
        //sc.Credentials = new System.Net.NetworkCredential("contact@example.com", "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)


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("no-reply@example.com");

//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 contact@example.com 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("abc@example.com");

//add the contact email address to the To list
mailMessage.To.Add(new MailAddress("contact@example.com"));

//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("abc@example.com");
    mailMessage.To.Add(new MailAddress("contact@example.com"));
    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("contact@example.com", "MyPassword");

    //send to only the contact@example.com 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 contact@example.com: <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;
}


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜