【发布时间】:2017-09-03 18:50:19
【问题描述】:
我想在用户选择电子邮件时向用户发送验证码,然后在 UserEmail 中向用户发送验证码,如果用户选择电话,则使用
向用户发送验证码在我的代码中,我采用了一个 DropDownList(with AutoPostBack=true) 使用该用户可以选择他们的选择
但我的代码不起作用
验证.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{ }
protected void dpd_SelectedIndexChanged(object sender, EventArgs e)
{
String email = Request.QueryString["email"];
String phn = "+91" + Request.QueryString["phn"];
if (!IsPostBack)
{
if (dpd.SelectedValue.Equals("Email"))
{
var chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var stringChars = new char[8];
var random = new Random();
for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
var finalString = new String(stringChars);
String mailbody = @"
<html><head></head><body><div style=background:#000099;border:1px solid
#000099;padding: 10px;><img src='+logo.png+' /></div><br /><br /><hr
style=color:#FF0000><p><strong>Hello User</strong>,<br /> <font face=Arial,
Helvetica, sans-serif color=#66CCFF size=+1>Please Verify Your your account
information</font></p><p> </p><p>Thanks For Joining Us...<br>
<strong>Gaurav Bothra</strong></p></body></html>";
// Specify the from and to email address
MailMessage mailMessage = new MailMessage("keystroke165@gmail.com", email);
// Specify the email body
mailMessage.IsBodyHtml = true;
mailMessage.Body = mailbody;
// Specify the email Subject
mailMessage.Subject = "Welcome to THERAPEUTIC";
// No need to specify the SMTP settings as these
// are already specified in web.config
SmtpClient smtpClient = new SmtpClient();
// Finall send the email message using Send() method
smtpClient.Send(mailMessage);
}
if (dpd.SelectedValue.Equals("Phone"))
{
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var stringChars = new char[8];
var random = new Random();
for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
var finalString = new String(stringChars);
var accountSid = "MYSIDXXXXX";
// Your Auth Token from twilio.com/console
var authToken = "MYTOKENXXXX";
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
to: new PhoneNumber(phn),
from: new PhoneNumber("MYTwilioNO"),
body: "Hello User????\nPlease Verify Your your account information\nyour otp is\n" + finalString);
///End
}
}
}
【问题讨论】:
-
描述不工作。你需要说出它在做什么,提及任何错误,描述你尝试过的其他事情。
-
没有错误但是邮件和短信收不到
-
您是否使用调试器单步执行代码以验证它通过您的代码采用了正确的路径?
-
我在代码中调试我的代码没有逻辑问题
-
真的吗?当您看到代码逐行执行时,它采用了您期望的路径?我不相信你。
标签: c# asp.net webforms twilio postback