0

重複の可能性:
Gmail を介して .NET でメールを送信する

このメール コードはローカルホスト、つまり自分のコンピューターでは機能していますが、サーバーで uopload すると機能しません。エラー: メールの送信に失敗しました。どこに問題があるのか​​教えてください。

 if (Session["userinfo"] != null)
     {

         lblTest.Text = Session["userinfo"].ToString();
         MailMessage msg = new MailMessage();
         msg.From = new MailAddress("shop.bcharya@gmail.com");
         msg.To.Add(new MailAddress("bcc@dr.com"));
         msg.To.Add(new MailAddress("info@yzentech.com"));
         msg.Subject = "Mail from BcharyaCorporation.online shopping site";
         msg.Body = ""+lblTest.Text+"  wants to buy some products. please contact with him/her";
         SmtpClient sc = new SmtpClient();
         sc.Host = "smtp.gmail.com";
         // sc.Port = 25;
         sc.Credentials = new NetworkCredential("shop.bcharya@gmail.com", "mypassword");
         sc.EnableSsl = true;
         try
         {
             sc.Send(msg);
             lblPayment.Text = "Sorry. Currently we are out of online payment service. We will contact you for payment process. Thank you for buying this product.";

         }
         catch (Exception ex)
         {
             lblPayment.Text=ex.Message.ToString();
             Response.Write(ex.Message);
         }

     }
4

4 に答える 4

1

SMTPサーバーがそれをサポートしている場合(GmailやHotmailなど)にのみ、ポート587とSSLを使用します。一部のサーバーはポート25のみを使用し、SSLは使用しません。

于 2012-11-21T08:35:46.473 に答える
1

Gmailのメール設定の場合は、ポート番号も追加します

sc.Port = 587;

この行の後

sc.Host = "smtp.gmail.com";
于 2012-11-21T07:31:47.877 に答える
0

以下の方法を使用して確認します。

SmtpClient sc = 新しい SmtpClient(文字列); // 指定された SMTP サーバーを使用して電子メールを送信します

于 2012-11-21T07:59:49.123 に答える
0

以下のコードを使用して、電子メールを送信できます。ここでは、エラーの詳細を電子メールで送信するのが 1 つの方法です。メールを送信するには、このコードを試してください。

using System.Web.Mail
public static bool SendErrorEmail(string to, string cc, string bcc, string subject,    string body, MailPriority priority, bool isHtml)
{
 try
{
using (SmtpClient smtpClient = new SmtpClient())
{
using (MailMessage message = new MailMessage())
 {
 MailAddress fromAddress = new MailAddress(“yourmail@domain.com”, “Your name”);
 // You can specify the host name or ipaddress of your server
 smtpClient.Host = “mail.yourdomain.com”; //you can specify mail server IP address here
 //Default port is 25
 smtpClient.Port = 25;
 NetworkCredential info = new NetworkCredential(“yourmail@domain.com”, “your password”);
 smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtpClient.UseDefaultCredentials = false;
 smtpClient.Credentials = info;
 //From address will be given as a MailAddress Object
 message.From = from;
 message.Priority = priority;
 // To address collection of MailAddress
 message.To.Add(to);
 message.Subject = subject;
 // CC and BCC optional
 if (cc.Length > 0)
 {
 message.CC.Add(cc);
 }
 if (bcc.Length > 0)
 {
 message.Bcc.Add(bcc);
 }
 //Body can be Html or text format;Specify true if it is html message
 message.IsBodyHtml = isHtml;
 // Message body content
 message.Body = body;
 // Send SMTP mail
 smtpClient.Send(message);
 }
 }
 return true;
 }
 catch (Exception ee)
 {
 Logger.LogError(ee, “Error while sending email to ” + toAddress);
 throw;
 }
}
于 2012-11-21T09:55:44.170 に答える