1

yahoo から yahoo にメールを送信したいのですが、送信できませんでした。私は受信したネットワークを使用します。コード認証情報を確認してください。例外やエラーはありませんが、メールボックスを開くとメールがありません。成功したフルテキストを表示するを使用しましたlabelが、その時点では正常に表示されません。

.aspx コード:

<form id="form1" runat="server">

    Message from: <asp:TextBox ID="text1" runat="server"></asp:TextBox>
    Message To: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    Message subject: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

   <asp:Button ID="b1" runat="server" OnClick="click" />

   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>

.aspx.cs:

public void click(object sender, EventArgs e)
{
    try
    {
         //mail message
         MailMessage mM = new MailMessage();

         //Mail Address
         mM.From = new MailAddress(text1.Text);

         //emailid to send
         mM.To.Add(TextBox1.Text);

         //your subject line of the message
         mM.Subject = "your subject line will go here.";

         //now attached the file
         //mM.Attachments.Add(new Attachment(@"C:\\attachedfile.jpg"));

         //add the body of the email
         mM.Body = "Your Body of the email.";
         mM.IsBodyHtml = false;

         //SMTP 
         SmtpClient SmtpServer = new SmtpClient();

         //your credential will go here
         SmtpServer.Credentials = new 

         System.Net.NetworkCredential("username", "password");

         //port number to login yahoo server
         SmtpServer.Port = 587;

         //yahoo host name
         SmtpServer.Host = "smtp.mail.yahoo.com";
         SmtpServer.EnableSsl = true;

         SmtpServer.Send(mM);
         Label1.Text = "successfull";
         //Send the email

         //end of try block
         //end of catch
     }
     catch(Exception ee){
         Console.Write(ee);
     }
}
4

1 に答える 1

0

コード自体に問題があるとは思いません。私はあなたのコードとほとんど同じコードを使用していますが、うまく機能します。

設定に問題があると思います。確認してください。

  1. TextBox1 の受信者の電子メール アドレスが既に存在する場合
  2. 資格情報のユーザー名とパスワードがすべて正しい場合

また、コードで Port プロパティを設定しません。すべてが正しければ、例外情報をここに表示してください。

于 2012-09-14T08:28:00.670 に答える