email

i have a working code thanks to EmailArchitect i took his code and we got it working in vs2013 u just need to download the easendmail and grab the files easendmailobj header, easendmailobj inline file, stdafx.cpp, stdafx header, and targetver header form C:\Program Files (x86)\EASendMail\Samples_VC\simple.vcNative and use the working code below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// The following example codes demonstrate sending email message using Gmail SMTP server
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

#define _AFXDLL
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib;

int _tmain(int argc, char* argv[])
{
	::CoInitialize(NULL);

	try
	{
		IMailPtr oSmtp = NULL;
		oSmtp.CreateInstance("EASendMailObj.Mail");
		oSmtp->LicenseCode = ("TryIt");

		// Set your gmail email address
		oSmtp->FromAddr = ("gmailid@gmail.com");

		// Add recipient email address
		oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

		// Set email subject
		oSmtp->Subject = ("simple email from Visual C++ with gmail account");

		// Set email body
		oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

		// Gmail SMTP server address
		oSmtp->ServerAddr = ("smtp.gmail.com");

		// If you want to use direct SSL 465 port,
		// Please add this line, otherwise TLS will be used.
		// oSmtp->ServerPort = 465;

		// detect SSL/TLS automatically
		oSmtp->SSL_init();

		// Gmail user authentication should use your
		// Gmail email address as the user name.
		// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
		oSmtp->UserName = ("gmailid@gmail.com");
		oSmtp->Password = ("password");

		printf("Start to send email via gmail account ...\r\n");

		if (oSmtp->SendMail() == 0)//program crashes here
		{
			_tprintf(_T("email was sent successfully!\r\n"));
		}
		else
		{
			_tprintf(_T("failed to send email with the following error: %s\r\n"),
				(const TCHAR*)oSmtp->GetLastErrDescription());
		}

		if (oSmtp != NULL)
			oSmtp.Release();
	}

	catch (_com_error &ep)
	{
		_tprintf(_T("Error: %s"), (const TCHAR*)ep.Description());
	}

	return 0;
}
Last edited on
Why not write one yourself? Don't just ask for the solution because you couldn't figure it out. Work harder.
Last edited on
i have no idea of how to write a code that allows me to send email
Look at your other topic that you wrote. You still haven't linked the libraries. You don't even know if your code works or not.
i found another code thats shorter and runs but it crashes where i put a comment that says "program crashes here"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// The following example codes demonstrate sending email message using Gmail SMTP server
// To get full sample projects, please download and install EASendMail on your machine.
// To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

#define _AFXDLL
#include "stdafx.h" 

#include "easendmailobj.tlh" 
using namespace EASendMailObjLib;

int _tmain(int argc, char* argv[])
{
	::CoInitialize(NULL);

	try
	{
		IMailPtr oSmtp = NULL;
		oSmtp.CreateInstance("EASendMailObj.Mail");
		oSmtp->LicenseCode = ("TryIt");

		// Set your gmail email address
		oSmtp->FromAddr = ("gmailid@gmail.com");

		// Add recipient email address
		oSmtp->AddRecipientEx(("gmailid@gmail.com"), 0);

		// Set email subject
		oSmtp->Subject = ("simple email from Visual C++ with gmail account");

		// Set email body
		oSmtp->BodyText = ("this is a test email sent from Visual C++ project with Gmail");

		// Gmail SMTP server address
		oSmtp->ServerAddr = ("smtp.gmail.com");

		// If you want to use direct SSL 465 port,
		// Please add this line, otherwise TLS will be used.
		// oSmtp->ServerPort = 465;

		// detect SSL/TLS automatically
		oSmtp->SSL_init();

		// Gmail user authentication should use your
		// Gmail email address as the user name.
		// For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
		oSmtp->UserName = ("gmailid@gmail.com");
		oSmtp->Password = ("****");

		printf("Start to send email via gmail account ...\r\n");

		if (oSmtp->SendMail() == 0)//program crashes here
		{
			printf("email was sent successfully!\r\n");
		}
		else
		{
			printf("failed to send email with the following error: %s\r\n"),
				(const TCHAR*)oSmtp->GetLastErrDescription();
		}

		if (oSmtp != NULL)
			oSmtp.Release();
	}

	catch (_com_error &ep)
	{
		_tprintf(_T("Error: %s"), (const TCHAR*)ep.Description());
	}

	return 0;
}
Just write your own code... You're not even trying. This example would run fine if you would just read the comments and followed directions. But no, you're just trying to take someone else's work and run it without doing anything. We cannot help you if you are not willing to do any work for yourself. No one is going to do everything for you just because you're lazy.

...After reading this, I realized that this post has a hostile tone to it... but this is because I'm getting sick and tired of you just ignoring advice given to you and still requesting help. I don't mean to offend you, but until you do something for yourself, no one is going to do anything for you.

Your posts show that you are not yet competent with the language. You shouldn't be attempting a email program yet. Focus on learning the language first. After you know the basics then you should come back to this task.
Last edited on
Topic archived. No new replies allowed.