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()
{
string PasswordLength = "12";
string NewPassword = "";
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 += "~,!,@,#,$,%,^,&,*,+,?";
char[] sep = { ',' };
string[] arr = allowedChars.Split(sep);
string IDString = "";
string temp = "";
Random rand = new Random();
for (int i = 0; i < Convert.ToInt32(PasswordLength); i++)
{
temp = arr[rand.Next(0, arr.Length)];
IDString += temp;
NewPassword = IDString;
}
return NewPassword;
}
protected void Button1_Click(object sender, EventArgs e)
{
{
string strSubject = "Your Password Has Been Reset";
string strFromEmail = "admin@i1tech.com";
string strFromName = "Administrator";
string strNewPassword = GeneratePassword().ToString();
try
{
MailMessage MailMsg = new MailMessage();
MailMsg.From = new MailAddress(strFromEmail);
MailMsg.Subject = strSubject;
MailMsg.To.Add(TextBox1.Text);
MailMsg.IsBodyHtml = true;
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";
SmtpClient smtp = new SmtpClient();
smtp.Host = "webmail.i1tech.com";
SmtpClient client = new SmtpClient();
client.Port = 465;
client.Host = "smtpout.asia.secureserver.net ";
System.Net.NetworkCredential basicCrenntial =
new System.Net.NetworkCredential("username", "password");
client.Send(MailMsg);
Label1.Text = "Message Sent Successfully";
}
catch (Exception ex)
{
Label1.Text = "Error: " + ex.ToString();
}
}
}
}
}
kindly help me