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
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";
Response.Write("Mail sent successfully");
catch (Exception x)
Response.Write("Your message was not sent: " + x.Message);