4

これが特に MvcMailer の質問だとは思いませんが (これは私が使用しているメーラーです)、Googleplex 検索を構成して、コンテキストに基づいてさまざまなアカウントから電子メールを送信する方法を見つけるのに苦労しています。

2 つの異なる電子メール アカウントから 2 つの電子メールを送信する必要があります。使ってみました

mailMessage.From = new MailAddress("some-other-email@gmail.com");

MvcMailer では、一時ディレクトリにダンプした電子メールにも表示されません。web.config にあるものとして表示されます: "some-email@gmail.com"。

これは、MvcMailer の web.config です。

<mailSettings>
      <!-- Method#1: Configure smtp server credentials -->
      <!--<smtp from="some-email@gmail.com">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="some-email@gmail.com" password="valid-password" />
      </smtp>-->
      <!-- Method#2: Dump emails to a local directory -->

            <smtp from="some-email@gmail.com" deliveryMethod="SpecifiedPickupDirectory">
                <network host="localhost" />
                <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\" />
            </smtp>

    </mailSettings>

これはメーラーコードです:

public virtual MailMessage EMailConsultation(EMailConsultationData model)
        {
            var mailMessage = new MailMessage { Subject = "INQUIRY: E-Mail Consultation" };

            mailMessage.From = new MailAddress("some-other-email@gmail.com");//I tested this to see if at the very least it would show up in the e-mail, but it didn't.

            mailMessage.To.Add(model.EMail);

            ViewData = new ViewDataDictionary(model);
            PopulateBody(mailMessage, viewName: "InquiryEMailConsultation");

            return mailMessage;
        }

繰り返しますが、上記のコードは電子メールを送信するために機能します。web.configのように「some-email@gmail.com」からではなく、指定した電子メールアドレスから送信するようにメーラーを設定する方法がわかりません。複数の MailMessage があり、別の電子メール アカウントから特定のメッセージを送信する必要があります。

ヘルプ/コード例をいただければ幸いです。

4

2 に答える 2

6

コードで独自の SmtpClient オブジェクトを作成し、それを使用して生成された電子メールを送信できます。また、web.config で 1 つの smtp 設定のみを使用します (既定の設定)。

MvcMailer の web.config で:

<mailSettings>
    <smtp from="some-email@gmail.com" deliveryMethod="SpecifiedPickupDirectory">
        <network host="localhost" />
        <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\" />
    </smtp>
</mailSettings>

と使用MyMailer.EMailConsultation().Send();

Google経由でメールを送信する必要がある場合(例)、これを使用します:

using (var googleSmtp = new SmtpClient("smtp.gmail.com", 587))
{
    googleSmtp.EnableSsl = true;
    googleSmtp.Credentials = new NetworkCredential("some-email@gmail.com", "valid-password");

    googleSmtp.Send(MyMailer.EMailConsultation());
}
于 2012-02-28T11:22:27.350 に答える
0

または、カスタム Web 構成セクションを作成して、複数のエントリをフォールバックとすべてで処理することもできます。http://www.coralys.com/Articles/Custom-ASPNET-Config-Sections.aspxを参照してください。

于 2012-05-28T16:37:21.443 に答える