IFsrmSetting::EmailTest 方法 (fsrm.h)
將電子郵件訊息傳送至指定的電子郵件位址。
語法
HRESULT EmailTest(
[in] BSTR mailTo
);
參數
[in] mailTo
電子郵件地址。 字串限制為 255 個字元。
傳回值
方法會傳回下列傳回碼:
備註
使用這個方法來測試 SmtpServer 屬性中指定的 SMTP 伺服器。 寄件者是在 MailFrom 屬性中指定, (無法設定為 “[管理員 Email]”) 。
主旨和郵件本文是預先定義的當地語系化文字。
範例
下列範例會示範如何呼叫這個方法。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <stdio.h>
#include <comutil.h>
#include <fsrm.h> // FSRM base objects and collections
#include <fsrmtlb_i.c> // contains CLSIDs
//
// Call the IFsrmSetting::EmailTest method to test the SMTP email server.
//
void wmain(void)
{
HRESULT hr = 0;
IFsrmSetting* pSettings = NULL;
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
wprintf(L"CoInitializeEx() failed, 0x%x.\n", hr);
exit(1);
}
hr = CoCreateInstance(CLSID_FsrmSetting,
NULL,
CLSCTX_LOCAL_SERVER,
__uuidof(IFsrmSetting),
reinterpret_cast<void**> (&pSettings));
if (FAILED(hr))
{
wprintf(L"CoCreateInstance(FsrmSetting) failed, 0x%x.\n", hr);
if (E_ACCESSDENIED == hr)
wprintf(L"Access denied. You must run the client with an elevated token.\n");
goto cleanup;
}
wprintf(L"Successfully created Setting object.\n");
// Specify the SMTP server to use for sending email.
hr = pSettings->put_SmtpServer(_bstr_t(L"<FQDNOFSMTPSERVER>"));
if (FAILED(hr))
{
wprintf(L"pSettings->put_SmtpServer failed, 0x%x.\n", hr);
goto cleanup;
}
// Test the specified SMTP server. If the test succeeds, you will find a
// predefined email message in C:\Inetpub\mailroot\Drop. You can use
// Outlook Express to read the message.
hr = pSettings->EmailTest(_bstr_t(L"admin@<FQDNOFSMTPSERVER>"));
if (FAILED(hr))
{
wprintf(L"pSettings->EmailTest failed, 0x%x.\n", hr);
goto cleanup;
}
wprintf(L"Successfully sent mail.\n");
cleanup:
if (pSettings)
pSettings->Release();
CoUninitialize();
}
規格需求
需求 | 值 |
---|---|
最低支援的用戶端 | 都不支援 |
最低支援的伺服器 | Windows Server 2008 |
目標平台 | Windows |
標頭 | fsrm.h (包括 FsrmQuota.h、FsrmReports.h、FsrmScreen.h) |
Dll | SrmSvc.dll |