How to send email?

Using C or C++.
   I am having a dificulty sending email. Please direct me in solving this problem. No MFC ( :

any of your tips will be appreciated.
thak you.
VirtualRealityAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ValentinConnect With a Mentor Commented:
if you want i can send to you a class of a LinkControl
it enable to put into your dialog a hyperlink control like
mailto:dragon.flamingo.ro
or
http://www.flamingo.ro
0
 
vachoohoCommented:
ShellExecute("mailto:me@mysite.com?subject=Something")

or MAPISendMail()

want sample code?

0
 
vachoohoCommented:
Here is some code for MAPI send mail

/////////////////////////////////////////////////////////////////////////////////////////////
// MAILING SUPPORT
/////////////////////////////////////////////////////////////////////////////////////////////

AFX_STATIC_DATA BOOL _afxIsMailAvail = (BOOL)-1;    // start out not determined

class _AFX_MAIL_STATE : public CNoTrackObject
{
public:
      HINSTANCE m_hInstMail;      // handle to MAPI32.DLL
      virtual ~_AFX_MAIL_STATE();
};

_AFX_MAIL_STATE::~_AFX_MAIL_STATE()
{
      if (m_hInstMail != NULL)
            ::FreeLibrary(m_hInstMail);
}

static _AFX_MAIL_STATE _afxMailState;

void SendViaMail(LPCTSTR szFileName, CWnd * pWnd)
{
      ASSERT(_afxIsMailAvail);   // update handler always gets called first
      ASSERT(pWnd);

      CWaitCursor wait;

      _AFX_MAIL_STATE * pMailState = &_afxMailState;
      if(pMailState->m_hInstMail == NULL)
            pMailState->m_hInstMail = ::LoadLibraryA("MAPI32.DLL");

      if(pMailState->m_hInstMail == NULL)
      {
            pWnd->MessageBox(MESSAGE_MAPILOADFAILED, MESSAGE_MAPICAPTION);
            return;
      }
      ASSERT(pMailState->m_hInstMail != NULL);

      ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
      (FARPROC&)lpfnSendMail = ::GetProcAddress(pMailState->m_hInstMail, "MAPISendMail");
      if(lpfnSendMail == NULL)
      {
            pWnd->MessageBox(MESSAGE_MAPINOTFOUND, MESSAGE_MAPICAPTION);
            return;
      }
      ASSERT(lpfnSendMail != NULL);

      // build file title
      CString strTitle;
      {
            TCHAR drive[_MAX_DRIVE];
            TCHAR dir[_MAX_DIR];
            TCHAR fname[_MAX_FNAME];
            TCHAR ext[_MAX_EXT];

            ::_tsplitpath(szFileName, drive, dir, fname, ext);
            
            CString strFName(fname);
            if((strFName.GetLength() > 0) && (strFName[strFName.GetLength() - 1] == '.'))
                        strFName = strFName.Left(strFName.GetLength() - 1);

            // ???? ough !!! UNICODE ???
            strTitle.Format(_T("%s%s"), strFName, ext);
      }
      
      // prepare the file description (for the attachment)
      MapiFileDesc fileDesc;
      memset(&fileDesc, 0, sizeof(fileDesc));
      fileDesc.nPosition = (ULONG)-1;
      fileDesc.lpszPathName = (char *)szFileName;
      fileDesc.lpszFileName = (LPTSTR)(LPCTSTR)strTitle;

      // prepare the message (empty with 1 attachment)
      MapiMessage message;
      memset(&message, 0, sizeof(message));
      message.nFileCount = 1;
      message.lpFiles = &fileDesc;

      // prepare for modal dialog box
      ::AfxGetApp()->EnableModeless(FALSE);
      
      HWND hWndTop;
      
      //CWnd * pParentWnd = pWnd->GetSafeOwner(NULL, &hWndTop);
      CWnd * pParentWnd = ::AfxGetMainWnd();
      hWndTop = pWnd->m_hWnd;

      // some extra precautions are required to use MAPISendMail as it
      // tends to enable the parent window in between dialogs (after
      // the login dialog, but before the send note dialog).
      pParentWnd->SetCapture();
      
      ::SetFocus(NULL);
      
      pParentWnd->m_nFlags |= WF_STAYDISABLED;

      int nError = lpfnSendMail(0, (ULONG)pParentWnd->GetSafeHwnd(), &message, MAPI_LOGON_UI|MAPI_DIALOG, 0);

      // after returning from the MAPISendMail call, the window must
      // be re-enabled and focus returned to the frame to undo the workaround
      // done before the MAPI call.
      ::ReleaseCapture();
      
      pParentWnd->m_nFlags &= ~WF_STAYDISABLED;

      pParentWnd->EnableWindow(TRUE);
      
      ::SetActiveWindow(NULL);
      
      pParentWnd->SetActiveWindow();
      pParentWnd->SetFocus();

      if(hWndTop != NULL)
            ::EnableWindow(hWndTop, TRUE);
      
      ::AfxGetApp()->EnableModeless(TRUE);

      if(nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
            pWnd->MessageBox(MESSAGE_MAPISENDFAILED, MESSAGE_MAPICAPTION);
}

BOOL MAPIEnabled()
{
      if (_afxIsMailAvail == (BOOL)-1)
      {
            _afxIsMailAvail = (::GetProfileInt(_T("MAIL"), _T("MAPI"), 0) != 0) && (::SearchPath(NULL, _T("MAPI32.DLL"), NULL, 0, NULL, NULL) != 0);
      }

      return _afxIsMailAvail;
}


Although here I use some MFC classes you will be able easy get rid of them and replace with API/your app functions.

Hope this helps

0
 
chensuCommented:
You'd better post the question to the Windows programming topic area since you are not using MFC.
0
All Courses

From novice to tech pro — start learning today.