I have a problem with sending an attachment using CSmtp class.
Here's the code on that link:
int SendMail()
{
bool bError = false;
try
{
CSmtp mail;
#define test_gmail_tls
#if defined(test_gmail_tls)
mail.SetSMTPServer("smtp.gmail.com",587);
mail.SetSecurityType(USE_TLS);
#elif defined(test_gmail_ssl)
mail.SetSMTPServer("smtp.gmail.com",465);
mail.SetSecurityType(USE_SSL);
#elif defined(test_hotmail_TLS)
mail.SetSMTPServer("smtp.live.com",25);
mail.SetSecurityType(USE_TLS);
#elif defined(test_aol_tls)
mail.SetSMTPServer("smtp.aol.com",587);
mail.SetSecurityType(USE_TLS);
#elif defined(test_yahoo_ssl)
mail.SetSMTPServer("plus.smtp.mail.yahoo.com",465);
mail.SetSecurityType(USE_SSL);
#endif
mail.SetLogin("email@email.com");
mail.SetPassword("password");
mail.SetSenderName("");
mail.SetSenderMail("email@email.com");
mail.SetReplyTo("");
mail.SetSubject("Subject");
mail.AddRecipient("email@email.com");
mail.SetXPriority(XPRIORITY_NORMAL);
mail.SetXMailer("The Bat! (v3.02) Professional");
mail.AddMsgLine("Hello,");
mail.AddMsgLine("you have been successfully registered!");
mail.AddMsgLine(" ");
mail.AddMsgLine("Username: ");
mail.AddMsgLine("Password: ");
mail.AddMsgLine(" ");
mail.AddMsgLine("See ya!");
mail.AddAttachment("C:\\Users\\Jenda\\AppData\\Roaming\\text.dat");
mail.Send();
}
catch(ECSmtp e)
{
std::cout << "Error: " << e.GetErrorText().c_str() << ".\n";
bError = true;
}
if(!bError)
std::cout << "Registration E-Mail was sent on given address.\n";
return 0;
}
When I comment the attachment line, it successfully send the e-mail. BUT when I try to send that attachment it seems it just stops there and does nothing - it doesn't return any error or anything. It just does nothing (it is responding though - according to task manager, you know).
Also, here is a secondary question: You see the attachment path (C:\Users\Jenda\AppData\Roaming\text.dat)? How could the program get information about the user (name) and how could I add it into the path so it works on every computer. C:\Users\ WINDOWSUSERNAME \...
That's it, thank you for all your responses and ideas.
P.S. I am using Windows7 32bit and Visual c++ Express 2010.