Click here to Skip to main content
15,886,689 members

sending verification mail during registration

chandrasekar_t asked:

Open original thread
Getting smtp exception so that mail is not sending to reciever by means of below code

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
 
namespace randompwdgeneration
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		}
		public string GeneratePassword()
		{
			//Since I'm big on security, I wanted to generate passwords that contained numbers, letters and special
			//characters - and not easily hacked.
			 
			//I started with creating three string variables.
			//This one tells you how many characters the string will contain.
			string PasswordLength = "12";
			//This one, is empty for now - but will ultimately hold the finised randomly generated password
			string NewPassword = "";
			 
			//This one tells you which characters are allowed in this new password
			string allowedChars = "";
			allowedChars = "1,2,3,4,5,6,7,8,9,0";
			allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
			allowedChars += "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
			allowedChars += "~,!,@,#,$,%,^,&,*,+,?";
			 
			//Then working with an array...
			 
			char[] sep = { ',' };
			string[] arr = allowedChars.Split(sep);
			 
			string IDString = "";
			string temp = "";
			 
			//utilize the "random" class
			Random rand = new Random();
			 
			//and lastly - loop through the generation process...
			for (int i = 0; i < Convert.ToInt32(PasswordLength); i++)
			{
				temp = arr[rand.Next(0, arr.Length)];
				IDString += temp;
				NewPassword = IDString;
				 
				//For Testing purposes, I used a label on the front end to show me the generated password.
				//lblProduct.Text = IDString;
			}
		 
			return NewPassword;
		}
		 
		protected void Button1_Click(object sender, EventArgs e)
		{
			{
				//create your variables
				string strSubject = "Your Password Has Been Reset";
				string strFromEmail = "admin@i1tech.com";
				string strFromName = "Administrator";
				string strNewPassword = GeneratePassword().ToString(); //This is where you'd call the new password string.
				try
				{
					//create the new mail message[/color]
					MailMessage MailMsg = new MailMessage();
					//cretate the FROM[/color]
					MailMsg.From = new MailAddress(strFromEmail);
					//create the subject[/color]
					MailMsg.Subject = strSubject;
					//We obviously need to create the TO - otherwise it goes nowhere.
					MailMsg.To.Add(TextBox1.Text); //assuming there was a form to fill out and they put the right email address in.
					MailMsg.IsBodyHtml = true; //I decided to make it html - so I could format the text.
					MailMsg.Body = "The following email was sent to you by " + strFromName + ".";
					MailMsg.Body += "Apparently, you needed your password reset - So here it is: ";
					MailMsg.Body += "New Password " + strNewPassword + "";
					MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now. ";
					MailMsg.Body += "Click the following link to change your password:";
					MailMsg.Body += "admin@i1tech.com";
					//utilizing SMTP (simple mail transfer protocol)
					SmtpClient smtp = new SmtpClient();
					smtp.Host = "webmail.i1tech.com"; //if my domain had a way of sending out emails.
					 
					SmtpClient client = new SmtpClient();
					client.Port = 465;
					//client.EnableSsl = true;
					//client.Credentials = new System.Net.NetworkCredential
					//("username", "password");
					//client.EnableSsl = true;
					client.Host = "smtpout.asia.secureserver.net ";//smtpout.asia.secureserver.net
					//System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
					////This object stores the authentication values
					 
					System.Net.NetworkCredential basicCrenntial =
					new System.Net.NetworkCredential("username", "password");
					 
					//mailClient.UseDefaultCredentials = false;
					 
					//mailClient.Credentials = basicCrenntial;
					 
					client.Send(MailMsg); //send it
					Label1.Text = "Message Sent Successfully"; //tell the person that the email was sent.
				}
				catch (Exception ex)
				{
					Label1.Text = "Error: " + ex.ToString(); //or tell the person that they screwed up and it's all their fault.... or what the actual error was.
				}
			}
		}
	}
}
kindly help me
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900