おはよう。私はどのように同じヘルパークラスの別の部分からヘルパークラス内の関数を呼び出すことができます把握しようとしているつもりですか?ヘルパークラスは、SMTP Sending Helperクラスを使用しようとしています。あまりにも多くのコーディングをする前に、これを実行できることを確認したいと思います。クラスライブラリ内でヘルパークラスを呼び出すWindowsサービス
ヘルパークラスAは自分のメール送信者ヘルパーです ヘルパークラスBは、電子メールの受信者を決定した後、電子メール警告を送信します。
ここまで私がこれまで何をしようとしています。
ServiceLibrary.SmtpHelperClass smtp = new SmtpHelperClass();
私はSMTPを使用しようとすると:私は単にオブジェクトを作成するには、このようなヘルパークラスを呼び出すことができた印象の下にあったクラスB
内部クラスAのために使用して句を設定します。 SendMail(...);それは誤りです。これがどのように行われたかについて、誰かが何らかの光を当てることができるかこれらのヘルパークラスは、Windowsサービスで動作します。私の計画は、予定された実行時間に基づいて他のヘルパーに電話することです。
発信者コードがそうのように書かれている:
class AuditReminders
{
SmtpHelperClass mailHelper = new SmtpHelperClass();
mailHelper.SendMailMessage();
}
私はSendMailMessageは、このコンテキスト内に存在しないというエラーを取得します。私SmtpHelperClassはとてもように書かれている:
using System;
using System.Net.Mail;
namespace ServiceLibrary
{
public class SmtpHelperClass
{
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
System.Diagnostics.EventLog evlFormatter = new System.Diagnostics.EventLog();
evlFormatter.Source = "WAST Windows Service";
evlFormatter.Log = "WAST Windows Service Log";
// Instantiate a new instance of MailMessage
MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to));
// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{
// Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
string[] words = cc.Split(';');
foreach (string word in words)
try
{
mMailMessage.CC.Add(new MailAddress(word));
}
catch (Exception ex)
{
// place writer for event viewer here
evlFormatter.WriteEntry("Error encountered: " + ex.ToString());
}
// Set the CC address of the mail message
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body;
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.High;
// Instantiate a new instance of SmtpClient
SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
mSmtpClient.Send(mMailMessage);
}
}
}
エラーは何ですか?クラス自体とは何の関係もないかもしれません。 – Tim
私はこのようにテストのためにこれを書いた: クラスAuditReminders { SmtpHelperClass mailHelper = new SmtpHelperClass(); mailHelper.SendMailMessage(); } mailHelperは現在のコンテキストに存在しません。 – bbcompent1
書きましたか?必要に応じて質問を編集して、より多くの情報とコードを追加することができます。 – Tim