Create C# webform for email submission using SMTP

Hello,
I'm a newbie and completely lost.

I am trying to create a webform in C# that will send an email to my email address with the code below. I need to send a username and password with the code so that the server connection can be made.

When I build the program, I am told that system.net.mail.mailmessage doesn't have definitions for username, password, authorization, port, helodomain, mailfrom etc.

I think i'm missing a namespace (or more) but I'm having difficulty figuring out which one(s).

Please help me get my code working

Thanks


using System.Net.Mail;

        try
        {
            MailMessage mailObj = new MailMessage();

            //set user authentication
           mailObj.UserName = "LogonServerName";
           mailObj.Password = "pleasehelp";

            //specifies the authentication mechanism.
            mailObj.AuthType = SmtpAuthType.AuthAuto;

            //set SSL connection
            mailObj.ConnectType = SmtpConnectType.ConnectSSLAuto;

            //set smtp server port (port 25 blocked by my isp so using alternate one)
            mailObj.Port = ###;

            //set helo domain
            mailObj.HeloDomain = "myURL.com";

            //set delivery-report address
            mailObj.MailFrom = "you@myURL.com";

            mailObj.From = "DoNotRespond@myURL.com";
            mailObj.To = "me@myURL.com";
            mailObj.Subject = "Submission Form";
            mailObj.Body = "This is sample text";
            mailObj.BodyFormat = MailFormat.Text;
            mailObj.SmtpServer = "myURL.com";
            mailObj.Send(mailObj);
            Response.Write("Mail sent successfully");
        }
        catch (Exception x)
        {
            Response.Write("Your message was not sent: " + x.Message);
        }
vynette10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vynette10Author Commented:
Thank you for your response. I am more clueless than I realized. I'm going to start posting the entire aspx.cs page.

I made the changes suggested above and now have new build errors. . .

1.Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).   //*this causes Default2 to be underlined*

2.'ASP.submitform_aspx.GetTypeHashCode()': no suitable method found to override

3.'ASP.submitform_aspx.ProcessRequest(System.Web.HttpContext)': no suitable method found to override      
      
4.'ASP.submitform_aspx' does not implement interface member 'System.Web.IHttpHandler.IsReusable'      

Code is now:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace Examples.SmptExamples.Async
{

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

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                System.Net.Mail.MailMessage mailObj = new System.Net.Mail.MailMessage();

                //set user authentication
                mailObj.UserName = "LogonServerAccountName";
                mailObj.Password = "pleasehelp";

                //specifies the authentication mechanism.
                mailObj.AuthType = SmtpAuthType.AuthAuto;

                //set SSL connection
                mailObj.ConnectType = SmtpConnectType.ConnectSSLAuto;

                //set smtp server port (Port 25 blocked by my isp so using alternate one)
                mailObj.Port = ###;

                //set helo domain
                mailObj.HeloDomain = "myURL.com";

                //set delivery-report address
                mailObj.MailFrom = "you@myURL.com";

                mailObj.From = "me@myURL.com";
                mailObj.To.Add = "DoNotRespond@myURL.com";

                mailObj.Subject = " Submission Form";
                mailObj.Body = "This is sample text";
                mailObj.BodyFormat = MailFormat.Text;
                mailObj.SmtpServer = "myURL.com";
                mailObj.Send(mailObj);
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("myURL.com");
                Response.Write("Mail sent successfully");
            }
            catch (Exception x)
            {
                Response.Write("Your message was not sent: " + x.Message);
            }

        }
        protected void FirstNameTxt_TextChanged(object sender, EventArgs e)
        {

        }
        protected void LastNameTxt_TextChanged(object sender, EventArgs e)
        {

        }
        protected void TitleTxt_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
0
Smart_ManCommented:
grrrrr .. i hate to go through code lines searching for errors. looool.

cannt we just talk about teh ideas ?! so the experince is on me and the work is on you ?? loooool


from the glance i took at the errors. you should use the autosense in teh IDE so you do not use somthign that is not there. make sure of the definition of teh calsses/liberaries/bla bla , whatever you are inheriting from above the lines you are going to call.

.... ummm...

what about having more in-depth look and get back ?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vynette10Author Commented:
I'm glad you said that. I'd love to talk about the concepts so I can learn more. I was afraid that if the discussion got too long or there were too many time gaps in the conversation, you would lose interest.

I'm having problems with the automatic code generated by Visual Studio. I have tried several ways to code this form. The previous ways I coded things created automatic code I need to change, but I don't know the right way to do it.

I have discovered commenting out this code leads to either more errors or new automatically generated code that recreates the same errors. Deletion of sections of code and deletion of the file the code is in also lead to more errors.

When I had this problem previously, I would create a new file and start over.  I would leave the old file (and it's automatically generated code) in the project. However, I have finally gotten the page to look how I want it to look and am reluctant to start over for the 3rd time.

Any suggestions?
0
Smart_ManCommented:
one thing to know : do NOT fight the system , lool , ofcourse t applies for teh political , economical .... things so you are safe . but the same is about microsoft too.

hehehe

looks like all your ways were just opposing teh auto-generated code whih is supposed tomake things easier for you and not harder.

anyways, waht is your problems with the auto-automated code / your code, so we can try some solutions for that , either by having new resources to learn from or applying some concepts , .....

please feed me back with the problems the way an expert would do .. the ideas. not the code lines. ;) thnx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vynette10Author Commented:
Please delete the question. The answers were not helpful to me and I doubt they will be helpful to anyone else.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Servers

From novice to tech pro — start learning today.