Metode IFsrmSetting::EmailTest (fsrm.h)
Kirim pesan email ke alamat email yang ditentukan.
Sintaks
HRESULT EmailTest(
[in] BSTR mailTo
);
Parameter
[in] mailTo
Alamat email. String dibatasi hingga 255 karakter.
Nilai kembali
Metode mengembalikan kode pengembalian berikut:
Keterangan
Gunakan metode ini untuk menguji server SMTP yang ditentukan dalam properti SmtpServer . Pengirim ditentukan dalam properti MailFrom (tidak dapat diatur ke "[Admin Email]").
Subjek dan isi pesan adalah teks yang telah ditentukan sebelumnya dan dilokalkan.
Contoh
Contoh berikut menunjukkan cara memanggil metode ini.
#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();
}
Persyaratan
Persyaratan | Nilai |
---|---|
Klien minimum yang didukung | Tidak ada yang didukung |
Server minimum yang didukung | Windows Server 2008 |
Target Platform | Windows |
Header | fsrm.h (termasuk FsrmQuota.h, FsrmReports.h, FsrmScreen.h) |
DLL | SrmSvc.dll |