0
我試圖通過電子郵件發送密鑰碼,但是每次發生此錯誤時: - 「服務器拒絕發件人地址。服務器響應爲:530 5.7.0必須首先發出STARTTLS命令。 e6sm29167643pfj.71-gsmtp.「。我認爲問題是與SendMails(),但我沒有得到什麼問題。請幫助我out.I使用Visual Studio社區2015年?錯誤: - 服務器拒絕發件人地址。服務器響應是:530 5.7.0必須首先發出STARTTLS命令。 e6sm29167643pfj.71 - gsmtp
下面是代碼: -
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;
using System.Web.Util;
public partial class admin_ExamSchedule : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int examtypeid = Convert.ToInt32(Session["examtypeid"].ToString());
ddlExamIdNotAttempted.DataSource = objAttemptexam.getNotAttemptedExamId(examtypeid);
ddlExamIdNotAttempted.DataValueField = "ExamId";
ddlExamIdNotAttempted.DataTextField = "ExamName";
ddlExamIdNotAttempted.DataBind();
// Response.Write("<script>alert('Must Select Any One')</script>");
//ddlExamIdAttempted.DataSource = objAttemptexam.getAttemptedExamId();
//ddlExamIdAttempted.DataValueField = "ExamId";
//ddlExamIdAttempted.DataTextField = "ExamName";
//ddlExamIdAttempted.DataBind();
}
}
BALexam objAttemptexam = new BALexam();
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
objAttemptexam.uid = Convert.ToInt32(Session["uid"].ToString());
objAttemptexam.ExamReqDate = Convert.ToDateTime(Session["preferdate"]).ToString();
objAttemptexam.ExamAssignDate =txtAssignExamDate.Text;
objAttemptexam.ExamId = Convert.ToInt32(ddlExamIdNotAttempted.SelectedValue);
objAttemptexam.ExamRequestId = Convert.ToInt32(Session["ExamRequestId"].ToString());
// objAttemptexam.UserName = Session["User"].ToString();
objAttemptexam.KeyCode = txtKeyCode.Text;
string strMsg;
SendMails();
int i = objAttemptexam.InsertScheduleExam(out strMsg);
if (i > 1)
{
ClearData();
LblMsg.Text = strMsg;
}
else
LblMsg.Text = strMsg;
}
catch (Exception ex)
{
LblMsg.Text = ex.Message;
}
}
void SendMails()
{
MailMessage objMail = new MailMessage();
objMail.From = "[email protected]";
objMail.To = "[email protected]";
objMail.Subject = "OnLineExam Schedule.";
objMail.BodyFormat = MailFormat.Html;
objMail.Body = "Your Key : " + txtKeyCode.Text + "" + "\n" +
"Your ExamId : " + Convert.ToInt32(ddlExamIdNotAttempted.SelectedValue) + "" + "\n" +
"Your ExamDate : " + txtAssignExamDate.Text;
SmtpMail.SmtpServer = "smtp.gmail.com";
SmtpMail.Send(objMail);
Page.RegisterClientScriptBlock("Dhanush", "<script>alert('Key Send to Student Successfully...')</script>");
}
private void ClearData()
{
txtAssignExamDate.Text = txtKeyCode.Text = "";
}
protected void ddlExamIdAttempted_DataBound(object sender, EventArgs e)
{
ddlExamIdNotAttempted.Items.Insert(0, "--Select--");
}
protected void ddlExamIdNotAttempted_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void LB_Click(object sender, EventArgs e)
{
Response.Redirect("frmShowExamRequest.aspx");
}
}