Sending mail through asp.net form

Discussion in 'Email' started by solan, May 7, 2011.

  1. Hello all,
    that's my first time at Winhost, and i need to know what are the details to put on the web.config file, and if my cs file will work here without change.

    the cs file code:
    Code:
    public partial class Controls_ContactForm : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (txtPhoneHome.Text != string.Empty || txtPhoneBusiness.Text != string.Empty)
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string fileName = Server.MapPath("~/****_****/ContactForm.txt");
                string mailBody = System.IO.File.ReadAllText(fileName);
    
                mailBody = mailBody.Replace("##Name##", txtName.Text);
                mailBody = mailBody.Replace("##Item##", txtName.Text);
                mailBody = mailBody.Replace("##Email##", txtEmailAddress.Text);
                mailBody = mailBody.Replace("##HomePhone##", txtPhoneHome.Text);
                mailBody = mailBody.Replace("##BusinessPhone##", txtPhoneBusiness.Text);
                mailBody = mailBody.Replace("##Comments##", txtComments.Text);
    
                MailMessage myMessage = new MailMessage();
                myMessage.Subject = "You have a new message from your site (domainname.com)";
                myMessage.Body = mailBody;
    
                myMessage.From = new MailAddress("[email protected]", "domainname.co.il");
                myMessage.To.Add(new MailAddress("[email protected]", "Dear domainname"));
    
                SmtpClient mySmtpClient = new SmtpClient();
                mySmtpClient.Send(myMessage);
    
                lblMessage.Visible = true;
                FormTable.Visible = false;
                System.Threading.Thread.Sleep(5000);
    
            }
        }
    }
    the web.config file:
    Code:
    	<system.net>
    		<mailSettings>
    			<smtp deliveryMethod="Network" from="domainname &lt;[email protected]&gt;">
    				<network host="mail.domainname.co.il"/>
    			</smtp>
    		</mailSettings>
    	</system.net>

    well... that's the code.

    when i click the send button - nothing happent.

    offcourse the domainname is only for the forum, and i have the correct settings at the code.
     
    Last edited by a moderator: Oct 14, 2015
  2. i fixed it up !
    i forggot to take the <network host="mail.domainname.co.il"/> (web.config) from the dns manage ...

    ***.internetmailserver.net
     
  3. Ray

    Ray

    Good to hear that you figured it out.
     
  4. You you explain what you did to get it working, please? I'm experiencing the same problem: nothing happens when the email should be sending.

    I have the following in my web.config:

    Code:
      <system.net>
        <mailSettings>
          <smtp from="[email protected]">
            <network host="mail.jeffreygetzin.com" defaultCredentials="true" userName="[email protected]" />
          </smtp>
        </mailSettings>
      </system.net>
    
    
     
  5. Scratch that. I got it working by specifying the username and password for the email account. I really don't like having to do that. Since it's running on your machine, why can't it use SMTP without authentication?

    Jeff
     
  6. Glad you got it working.

    We force the authentication in an effort to identify spammers. If the server allows unauthenticated sending, determining which account is responsible for spam is very difficult. With authentication we know immediately and can take action.

    By "spammers" I don't mean legitimate accounts sending a lot of mail, but rather fraudulent accounts that are set up just to send spam. Unfortunately we have to deal with those every day.
     
  7. I'm concerned that if someone gets access to my web.config, he can get my authentication information.
     
  8. web.config isn't readable from the web, it's specifically disallowed in IIS. So unless someone has access to your files, via FTP or some other method (in other words, they have your account login and password), it's protected.
     
  9. Having similar problem but can't figure it out...

    I have a WebMatrix site on Winhost and I need webmail to send a notification when a form is filled in. Before doing the "real" page I uploaded the email-sending sample pages from this tutorial. But I can't get it to work. The page with my form is here.

    I understand that Winhost requires that I pass SMTP authentication to the web app, so I tried adding JeffG's code (previous in this thread) to web.config. I added username and password as he suggested in his follow-up post. I must still have it wrong, because it's not working for me.
    <system.net>
    <mailSettings>
    <smtp from="[email protected]">
    <network host="mail.myDomain.com" defaultCredentials="true" userName="myUserName" password="myPassword" />
    </smtp>
    </mailSettings>
    </system.net>

    I would be very grateful for any suggestions. Thanks!!
     
  10. I used the OOTB starter site, plugged my mail server info in, and it worked immediately, so I doubt it is a Winhost problem.

    I did not use that tutorial, but my guess is you have a setting wrong, or your code is bad. You should not copy someone elses code of the net unless it specifically applies to your application. Also check if you can simply send and email from SmarterMail, and go from there.

    See this, too: http://portal.smartertools.com/KB/a1517/cannot-send-outgoing-email-messages.aspx

    Also, the internet infrastructure is strained under the heatwave, expect more frequent outages, delays, and bizarre behavior.
     

Share This Page