how to send mails from VC++ program without using outlook - Page 3
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 47

Thread: how to send mails from VC++ program without using outlook

  1. #31
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by sushb4u
    can i give any points or like something that??i m new to this forum...thats why i m asking this.
    How do I rate a thread?
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  2. #32
    Join Date
    Jun 2004
    Location
    England
    Posts
    90
    Quote Originally Posted by Andreas Masur
    Well...it sends the mail correctly, however the body is somehow empty...I need to test this further I guess...sorry about that...
    It works fine for me, u can additionally include subject etc...

    thank
    The most knowledgeable people are those who know that they know nothing.

  3. #33
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Quote Originally Posted by Tamerocyte
    It works fine for me, u can additionally include subject etc...
    Hmm...interesting...then it is supposed to be a problem with either my ISP or mail client...

    Well...thanks for the information...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  4. #34
    Join Date
    Mar 2002
    Posts
    18
    Quote Originally Posted by sushb4u
    it gives this error

    d:\vcprojects\m\m.cpp(165) : fatal error C1010: unexpected end of file while looking for precompiled header directive

    You need include this file: #include "stdafx.h" in m.cpp
    In the same cases, u need do that, it' Ok
    Last edited by lad; June 25th, 2005 at 12:58 PM.

  5. #35
    Join Date
    Jul 2009
    Posts
    23

    Re: how to send mails from VC++ program without using outlook

    Well, i rly like your code but... Most servers currently need TLS/SSL support, which i do not know how to implement.

  6. #36
    Join Date
    Jun 2005
    Posts
    315

    Re: how to send mails from VC++ program without using outlook


    You realise this threads over 5 years old?

  7. #37
    Join Date
    Sep 2009
    Posts
    2

    Re: how to send mails from VC++ program without using outlook

    Indeed.
    Well, any one has tried sending emails with SMTP Authentication under VIsual C++?
    It seems to be a useful feature.

    The following one using visual C++ but only support the VC++ 2005 and 2008.
    http://www.naughter.com/smtp.html

    I like VC++ 6 better for its reliable codes and smaller code size.

  8. #38
    Join Date
    Sep 2009
    Posts
    2

    Re: how to send mails from VC++ program without using outlook

    "Please note that as of v2.70, the code is now for Visual C++ 2005 or later. I will not be supporting VC 6 anymore for this code, so please don't email me requesting this<gg>. Remember VC 6 is now a ten year old compiler. It's now time to upgrade to VC 2005 or VC 2008!"

    Maybe someone can share the V2.70 or earlier edition while the author stopped providing aged releases.

  9. #39
    Join Date
    Nov 2009
    Posts
    1

    Re: how to send mails from VC++ program without using outlook

    I use this send mail vc++ code but it gives error error during call to recv<> reply:-1 - 10054 and remaing all lines.so give me solution,exactly what is the problem

  10. #40
    Join Date
    Dec 2009
    Posts
    2

    Re: how to send mails from VC++ program without using outlook

    I'm an old VB6 guy working my way through MSVC. At 56, it's hard to assimilate enough to write MSVC effectively before I'm retirement age! Your generous and cooperative attitude will help more people than you know. Thank you so much.

  11. #41
    Join Date
    May 2011
    Posts
    3

    Re: HELP

    Hello. When I run the program I get an error message like this. I would be glad if you help. Thank you in advance.

    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|10|warning: ignoring #pragma comment |
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|13|error: ISO C++ forbids declaration of 'VERSION_MAJOR' with no type|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|14|error: ISO C++ forbids declaration of 'VERSION_MINOR' with no type|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'void ShowUsage()':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|20|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|20|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'void Check(int, char*)':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|32|error: 'cerr' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|32|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'int main(int, char**)':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|60|error: 'ifstream' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|60|error: expected ';' before 'MsgFile'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|65|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|65|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|74|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|74|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|83|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|83|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|105|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|105|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|111|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|115|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|116|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|120|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|121|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|125|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|126|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|130|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|131|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|134|error: 'MsgFile' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|139|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|145|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|146|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|150|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|151|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|154|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|154|error: 'endl' was not declared in this scope|
    ||=== Build finished: 19 errors, 15 warnings (0 minutes, 0 seconds) ===|

  12. #42
    Join Date
    May 2011
    Posts
    3

    Re: HELP

    Quote Originally Posted by HkN View Post
    Hello. When I run the program I get an error message like this. I would be glad if you help. Thank you in advance.

    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|10|warning: ignoring #pragma comment |
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|13|error: ISO C++ forbids declaration of 'VERSION_MAJOR' with no type|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|14|error: ISO C++ forbids declaration of 'VERSION_MINOR' with no type|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'void ShowUsage()':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|20|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|20|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'void Check(int, char*)':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|32|error: 'cerr' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|32|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp||In function 'int main(int, char**)':|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|60|error: 'ifstream' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|60|error: expected ';' before 'MsgFile'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|65|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|65|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|74|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|74|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|83|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|83|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|105|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|105|error: 'endl' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|111|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|115|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|116|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|120|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|121|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|125|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|126|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|130|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|131|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|134|error: 'MsgFile' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|139|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|145|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|146|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|150|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|151|warning: deprecated conversion from string constant to 'char*'|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|154|error: 'cout' was not declared in this scope|
    C:\Users\Hkn\Desktop\calisma\fb\main.cpp|154|error: 'endl' was not declared in this scope|
    ||=== Build finished: 19 errors, 15 warnings (0 minutes, 0 seconds) ===|
    last right, then the error message as follows;

    C: \ Users \ HKN \ Desktop \ working \ fb \ main.cpp | 11 | warning: ignoring # pragma comment |
    C: \ Users \ HKN \ Desktop \ working \ fb \ main.cpp | 14 | error: ISO C + + forbids declaration of 'VERSION_MAJOR' with no type |
    C: \ Users \ HKN \ Desktop \ working \ fb \ main.cpp | 15 | error: ISO C + + forbids declaration of 'VERSION_MINOR' with no type |

    Codeblocks in the meantime, I use the IDE.

  13. #43
    Join Date
    May 2011
    Posts
    2

    Re: how to send mails from VC++ program without using outlook

    I am also having the problem with the code errors. The exact same, actually.

  14. #44
    Join Date
    May 2011
    Posts
    0

    Re: how to send mails from VC++ program without using outlook

    I m writting an application which calulates some results and send them thr e-mail.I want my VC++ program to send this mail to specified address without using Outlook Express or Microsoft Outlook...So You try to this link htttp://www.coolinterview.com
    Last edited by Radhaa; May 9th, 2011 at 11:30 PM.

  15. #45
    Join Date
    Oct 2011
    Posts
    1

    Re: how to send mails from VC++ program without using outlook

    Please someone help me im trying 1 week to use this code.

    I m getting error on this line : if(connect(hServer, (PSOCKADDR) &SockAddr, sizeof(SockAddr)))

    Please see error screenshot

    This is my code :


    #define WIN32_LEAN_AND_MEAN

    #include <stdio.h>
    #include <iostream>
    #include <fstream>
    #include <stdlib.h>
    //#include <fstream.h>
    //#include <iostream.h>
    #include <windows.h>
    #include <winsock2.h>

    using namespace std;

    #pragma comment(lib, "ws2_32.lib")

    // Insist on at least Winsock v1.1
    const int VERSION_MAJOR = 1;
    const int VERSION_MINOR = 1;

    #define CRLF "\r\n" // carriage-return/line feed pair

    void ShowUsage(void)
    {
    cout << "Usage: SENDMAIL mailserv to_addr from_addr messagefile" << endl
    << "Example: SENDMAIL smtp.myisp.com rcvr@elsewhere.com my_id@mydomain.com message.txt" << endl;

    exit(1);
    }

    // Basic error checking for send() and recv() functions
    void Check(int iStatus, char *szFunction)
    {
    if((iStatus != SOCKET_ERROR) && (iStatus))
    return;

    cerr << "Error during call to " << szFunction << ": " << iStatus << " - " << GetLastError() << endl;
    }

    int main(int argc, char *argv[])
    {
    int iProtocolPort = 587;
    char szSmtpServerName[64] = "smtp.gmail.com";
    char szToAddr[64] = "lester555@gmail.com";
    char szFromAddr[64] = "555lester@gmail.com";
    char szBuffer[4096] = "lester555@gmail.com";
    char szLine[255] = "vai vai vaiiii";
    char szMsgLine[255] = "vai vai vaiiii";
    SOCKET hServer;
    WSADATA WSData;
    LPHOSTENT lpHostEntry;
    LPSERVENT lpServEntry;
    SOCKADDR_IN SockAddr;

    argc = 5;

    // Check for four command-line args
    if(argc != 5)
    ShowUsage();

    // Load command-line args
    lstrcpy(szSmtpServerName, argv[1]);
    lstrcpy(szToAddr, argv[2]);
    lstrcpy(szFromAddr, argv[3]);

    // Create input stream for reading email message file
    string dir = "D:\\file.txt";
    ifstream MsgFile(dir);

    // Attempt to intialize WinSock (1.1 or later)
    if(WSAStartup(MAKEWORD(VERSION_MAJOR, VERSION_MINOR), &WSData))
    {
    cout << "Cannot find Winsock v" << VERSION_MAJOR << "." << VERSION_MINOR << " or later!" << endl;

    return 1;
    }

    // Lookup email server's IP address.
    lpHostEntry = gethostbyname(szSmtpServerName);

    if(!lpHostEntry)
    {
    cout << "Cannot find SMTP mail server " << szSmtpServerName << endl;

    return 1;
    }

    // Create a TCP/IP socket, no specific protocol
    hServer = socket(PF_INET, SOCK_STREAM, 0);
    if(hServer == INVALID_SOCKET)
    {
    cout << "Cannot open mail server socket" << endl;

    return 1;
    }

    // Get the mail service port
    lpServEntry = getservbyname("mail", 0);


    // Use the SMTP default port if no other port is specified
    if(!lpServEntry)
    iProtocolPort = htons(IPPORT_SMTP);
    else
    iProtocolPort = lpServEntry->s_port;
    //iProtocolPort = 587;

    // Setup a Socket Address structure
    SockAddr.sin_family = AF_INET;
    SockAddr.sin_port = iProtocolPort;
    SockAddr.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);

    // Connect the Socket

    if(connect(hServer, (PSOCKADDR) &SockAddr, sizeof(SockAddr)))
    {
    cout << "Error connecting to Server socket" << endl;

    DWORD err = ::GetLastError();

    LPVOID lpMsgBuf;

    FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER |
    FORMAT_MESSAGE_FROM_SYSTEM |
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL );

    MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
    cout << (LPCTSTR)lpMsgBuf << endl;
    system("pause");
    return 1;
    }

    // Receive initial response from SMTP server
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() Reply");

    // Send HELO server.com
    sprintf(szMsgLine, "HELO %s%s", szSmtpServerName, CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() HELO");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() HELO");

    // Send MAIL FROM: <sender@mydomain.com>
    sprintf(szMsgLine, "MAIL FROM:<%s>%s", szFromAddr, CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() MAIL FROM");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() MAIL FROM");

    // Send RCPT TO: <receiver@domain.com>
    sprintf(szMsgLine, "RCPT TO:<%s>%s", szToAddr, CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() RCPT TO");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() RCPT TO");

    // Send DATA
    sprintf(szMsgLine, "DATA%s", CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() DATA");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() DATA");

    // Send all lines of message body (using supplied text file)
    MsgFile.getline(szLine, sizeof(szLine)); // Get first line

    do // for each line of message text...
    {
    sprintf(szMsgLine, "%s%s", szLine, CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() message-line");
    MsgFile.getline(szLine, sizeof(szLine)); // get next line.
    } while(MsgFile.good());

    // Send blank line and a period
    sprintf(szMsgLine, "%s.%s", CRLF, CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() end-message");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() end-message");

    // Send QUIT
    sprintf(szMsgLine, "QUIT%s", CRLF);
    Check(send(hServer, szMsgLine, strlen(szMsgLine), 0), "send() QUIT");
    Check(recv(hServer, szBuffer, sizeof(szBuffer), 0), "recv() QUIT");

    // Report message has been sent
    cout << "Sent " << argv[4] << " as email message to " << szToAddr << endl;

    // Close server socket and prepare to exit.
    closesocket(hServer);

    WSACleanup();

    return 0;
    }
    Attached Images Attached Images  

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center