Receive emails on a web hosting email domain from any user visiting the site

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

say that I run this site www.example.com and I have id contact@example.com Now a new visitor visits my site and fills out a form to contact us. He fills

FROM - abc@yahoo.com Subject request Message. My question is ....

I want to send this message as an email to contact@example.com

And when sending mail successfully, I want to send this user-generated mail as confirmation.

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

I am trying to use 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; 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 when you try to send mail.

The mailbox name is not resolved. The server response was: sorry, your mail was administratively denied. (# 5.7.1)

+4
source share
2 answers

It looks like from your code you are indicating that the From email field is based on the email address that the user populates. Mail server mail should reject this and only allow email from the example.com domain name, or possibly the server name. I came across this before when your From field should be the source domain of the site ...

If you want the recipient of the form to respond directly, use the ReplyTo field, not

 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 helps ...

EDIT:

After you have edited your question, the above is still relevant. You probably cannot use the From address outside your own domain domain example.com . If you want to send two copies of the request (one for contact@example.com , and the other for the user as confirmation), you just need to add 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 confirmation email you can 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; } 
+1
source

Perhaps this is a question of Serverfault.com , any way

you need to check these parameters

Admin Home → Configuration → Email Settings → - Method for sending email = SendEmail

link 553 Sorry, your mail has been administratively refused . (# 5.7.1)

0
source

Source: https://habr.com/ru/post/1301496/


All Articles