2016-03-19 7 views
0

私はキーコードを電子メールで送信しようとしていますが、毎回このエラーが発生します: - "サーバーが送信者アドレスを拒否しました。サーバー応答:530 5.7.0最初にSTARTTLSコマンドを発行する必要があります。 e6sm29167643pfj.71 - gsmtp。 "となります。私は問題がSendMails()であると思うが、その問題は何か分かっていない。私を助けてください。私はVisual studio community 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"); 
} 
} 

答えて

0

はちょうどあなたのエラーメッセージを確認し、それが問題を明確に述べている:あなたは安全な接続を使用していないとGmailは安全でない接続を介して送信することはできません。 。

ところで、SmtpMailクラスは廃止されました。代わりにSystem.Net.SmtpClientを使用することをお勧めします。