Solved

Email Problem

Posted on 2004-09-23
11
209 Views
Last Modified: 2011-04-14
I'm new - really new-idiot level- at programming and trying understand and use the SendEmail.cpp from Axter.  I used the example SendEmail Simple function to send an email to myself and it worked great.  Now, I've been trying to modify and use the program to read addresses from a text file and send mail to these addresses using the BCC field. I've tried the examples but can't make them to work - don't know how.  Can someone please help me?  Thanks.  
0
Comment
Question by:jazamor
  • 7
  • 4
11 Comments
 
LVL 30

Expert Comment

by:Axter
Comment Utility
>>I've tried the examples but can't make them to work - don't know how.  Can someone
>>please help me?  Thanks.  

Can you post your code.
Exactly how did it not work?   Did it fail to compile, fail to run, fail to send email, fail to send attachement with email......????

Give us as much details as you can.
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Example:

const char* Hostname = "axter_x.com";
const char* UserID = "axter_x";
const char* To = "maisonave@axter_x.com";
const char* Subject = "This is a test email";
const char* Body = "Test body";
const char* UserPassword = "abc123";

const char* AttachedFile = "C:\\autoexec.bat";

SendEmailSimple(Hostname, UserID, To, Subject, Body, UserPassword, AttachedFile);
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
If you're using a string literal for your attached file, make sure that it has double \ characters

"c:\\windows\\system32\\somefile.txt"
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Where did you get the SendEmail.cpp file from.
Was it from a link to my web site, or was it a copy and paste on another question?
0
 

Author Comment

by:jazamor
Comment Utility
I'm sorry it's taken me so long to answer.  The code I used is yours exactly the way you have it.  I put in this from your examples

int main(int , char*)
      {
            const char* Hostname = "mailgate.sandia.gov";
            const char* UserID = "entrustt@sandia.gov";
            const char* To = "jazamor@sandia.gov";
            const char* Subject = "This is a test email";
            const char* Body = "Test body";
            SendEmailSimple(Hostname, UserID, To, Subject, Body);
            return 0;
      }      

const char CCListTest[][64] = {"jazamor@sandia.gov","jazamor@sandia.gov","jazamor@sandia.gov"};

const char BCCListTest[][64] = {"jazamor@sandia.gov","jazamor@sandia.gov","jazamor@sandia.gov"};

void ExampleFunctionToSendMailToMultipleToCC_AndBCC(const std::string &Hostname, const std::string &UserID, const std::string &UserPassword)
{//Example for Multiple TO fields CC and BCC field
      std::list<std::string> ToList;
      ToList.push_back(ToListTest[0]);
      ToList.push_back(ToListTest[1]);
      ToList.push_back(ToListTest[2]);
      std::list<std::string> CCList;
      CCList.push_back(CCListTest[0]);
      CCList.push_back(CCListTest[1]);
      CCList.push_back(CCListTest[2]);
      std::list<std::string> BCCList;
      BCCList.push_back(BCCListTest[0]);
      BCCList.push_back(BCCListTest[1]);
      BCCList.push_back(BCCListTest[2]);
      std::string Results = SendEmail(Hostname, UserID, UserPassword)(
            ToList,
            "*File Test x15x: Please ignore this email.",
            "Test from SendEmail.  Please ignore this email.",
            &CCList,
            &BCCList);
      if (Results != SendEmail::NO_ERRORS)
      {
            printf("Error:\r\n");
            printf(Results.c_str());
            printf("\r\n\r\nPress ENTER to quit\r\n");
            getchar();
      }
}

These are the errors I get.  My main problem is I don't understand what I'm doing.

Compiling...
SendEmail.cpp
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(556) : error C2065: 'ToListTest' : undeclared identifier
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(556) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(556) : error C2664: 'push_back' : cannot convert parameter 1 from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
        Reason: cannot convert from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
        No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(557) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(557) : error C2664: 'push_back' : cannot convert parameter 1 from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
        Reason: cannot convert from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
        No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(558) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\jazamor\Desktop\SendEMail\SendEmail.cpp(558) : error C2664: 'push_back' : cannot convert parameter 1 from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
        Reason: cannot convert from 'int' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
        No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.

SendEmail.obj - 7 error(s), 0 warning(s)
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:jazamor
Comment Utility
I believe I downloaded it from your web site.
0
 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
Comment Utility
It looks like you have modified the original SendEmail.cpp file.

The version posted on the web only has commented code with the keyword ToListTest

Also, line 556 on the posted version has the following:
      if (uc  < 26) return 'A'+uc;


Try downloading the file again, and use it without modifying it.
http://www.axter.com/code/SendEmail.cpp
http://www.axter.com/code/SendEmail.h

When you use SendEmail.cpp and SendEmail.h, you should be able to use them both without modifying the files.

You should call the functions or class from your code which should be in a different file.
Like:
main.cpp
or
myprogram.cpp

In your *.cpp file, add your main() function, and call the function from there.
0
 

Author Comment

by:jazamor
Comment Utility
Okay, If I understand what your saying.  I can use your example for multiple CC and BCC field, at the end of the SendEmail.cpp as is and call it from a main() function in myown.cpp ?
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
>>SendEmail.cpp as is and call it from a main() function in myown.cpp ?

That's correct.
0
 

Author Comment

by:jazamor
Comment Utility
Okay, I'll give it a try. Since I new at this would it be okay to accept your answer for now and then post another question to you later if I have problems.  Thanks for your help.
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
>>Thanks for your help.

Your welcome.

If you have any questions, or suggestions, feel free to posted here.

I have change this class before when I've received good suggestions for generic modification of the class.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now