在注册期间发送验证邮件 [英] sending verification mail during registration
问题描述
获取smtp异常,以便邮件不会通过以下代码发送给收件人
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Net;
使用System.Net.Mail;
使用System.Net.Mime;
使用System.Threading;使用System.ComponentModel
;
命名空间randompwdgeneration
{
public partial class _Default:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
}
公共字符串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 =;
//利用随机类
随机rand = new Random();
//最后 - 循环生成过程...
for(int i = 0; i< Convert.ToInt32(PasswordLength); i ++)
{
temp = arr [rand.Next(0,arr.Length)];
IDString + = temp;
NewPassword = IDString;
//为了测试目的,我在前端使用了一个标签来显示生成的密码。
//lblProduct.Text = IDString;
}
返回NewPassword;
}
protected void Button1_Click(object sender,EventArgs e)
{
{
//创建变量
string strSubject =您的密码已重置;
string strFromEmail =admin@i1tech.com;
string strFromName =Administrator;
string strNewPassword = GeneratePassword()。ToString(); //这是您调用新密码字符串的地方。
try
{
//创建新邮件[/ color]
MailMessage MailMsg = new MailMessage();
//创建FROM [/ color]
MailMsg.From = new MailAddress(strFromEmail);
//创建主题[/ color]
MailMsg.Subject = strSubject;
//我们显然需要创建TO - 否则它无处可去。
MailMsg.To.Add(TextBox1.Text); //假设有一个表格要填写,他们把正确的电子邮件地址放入。
MailMsg.IsBodyHtml = true; //我决定把它变成html - 所以我可以格式化文本。
MailMsg.Body =以下电子邮件是通过+ strFromName +发送给您的。;
MailMsg.Body + =显然,你需要重置密码 - 所以这里是:;
MailMsg.Body + =新密码+ strNewPassword +;
MailMsg.Body + =如果你没有要求这个,那么 - 哎呀,你现在可能想考虑改变它。;
MailMsg.Body + =点击以下链接更改密码:;
MailMsg.Body + =admin@i1tech.com;
//利用SMTP(简单邮件传输协议)
SmtpClient smtp = new SmtpClient();
smtp.Host =webmail.i1tech.com; //如果我的域名有办法发送电子邮件。
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 ();
////这个对象存储认证值
System.Net.NetworkCredential basicCrenntial =
new System.Net.NetworkCredential(username,password);
//mailClient.UseDefaultCredentials = false;
//mailClient.Credentials = basicCrenntial;
client.Send(MailMsg); //发送它
Label1.Text =消息已成功发送; //告诉该人该电子邮件已发送。
}
catch(exception ex)
{
Label1.Text =Error:+ ex.ToString(); //或告诉那个人他们搞砸了,这都是他们的错......或者实际的错误是什么。
}
}
}
}
}
请帮助我
< blockquote>,%,^,&,*,+,?;
//然后使用数组...
char [] sep = {' ',''};
string [] arr = allowedChars.Split(sep);
string IDString =;
string temp =;
//利用随机类
随机rand = new Random();
//最后 - 循环生成过程...
for (int i = 0; i< Convert.ToInt32(PasswordLength); i ++)
{
temp = arr [rand.Next(0,arr.Length)];
IDString + = temp;
NewPassword = IDString;
//为了测试目的,我在前端使用了一个标签来显示生成的密码。
//lblProduct.Text = IDString ;
}
返回NewPassword;
}
protected void Button1_Click(object sender,EventArgs e)
{
{
//创建变量
string strSubject =您的密码已重置;
string strFromEmail =admin@i1tech.com;
string strFromName =Administrator;
string strNewPassword = GeneratePassword()。ToString(); //这是您调用新密码字符串的地方。
try
{
//创建新邮件[/ color]
MailMessage MailMsg = new MailMessage();
//创建FROM [/ color]
MailMsg.From = new MailAddress(strFromEmail);
//创建主题[/ color]
MailMsg.Subject = strSubject;
//我们显然需要创建TO - 否则它无处可去。
MailMsg.To.Add(TextBox1.Text); //假设有一个表格要填写,他们把正确的电子邮件地址放入。
MailMsg.IsBodyHtml = true; //我决定把它变成html - 所以我可以格式化文本。
MailMsg.Body =以下电子邮件是通过+ strFromName +发送给您的。;
MailMsg.Body + =显然,你需要重置密码 - 所以这里是:;
MailMsg.Body + =新密码+ strNewPassword +;
MailMsg.Body + =如果你没有要求这个,那么 - 哎呀,你现在可能想考虑改变它。;
MailMsg.Body + =点击以下链接更改密码:;
MailMsg.Body + =admin@i1tech.com;
//利用SMTP(简单邮件传输协议)
SmtpClient smtp = new SmtpClient();
smtp.Host =webmail.i1tech.com; //如果我的域名有办法发送电子邮件。
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 ();
////这个对象存储认证值
System.Net.NetworkCredential basicCrenntial =
new System.Net.NetworkCredential(username,password);
//mailClient.UseDefaultCredentials = false;
//mailClient.Credentials = basicCrenntial;
client.Send(MailMsg); //发送它
Label1.Text =消息已成功发送; //告诉该人该电子邮件已发送。
}
catch(exception ex)
{
Label1.Text =Error:+ ex.ToString(); //或告诉那个人他们搞砸了,这都是他们的错......或者实际的错误是什么。
}
}
}
}
}
请帮助我
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
,%,^,&,*,+,?"; //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
这篇关于在注册期间发送验证邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!