Wednesday, January 11, 2012

create mail message object.

// create mail message object

MailMessage mail = new MailMessage();



mail.From = ""; // put the from address here

mail.To = ""; // put to address here

mail.Subject = ""; // put subject here

mail.Body = ""; // put body of email here

SmtpMail.SmtpServer = ""; // put smtp server you will use here

// and then send the mail

SmtpMail.Send(mail);



Here goes the program vc++ code



#define _CRTDBG_MAP_ALLOC

#include "windows.h"

#include "crtdbg.h"

#include "string.h"



#include "CkSettings.h"

#include "CkEmail.h"

#include "CkEmailBundle.h"

#include "CkMailMan.h"

#include "CkString.h"

#include "CkByteData.h"



void EmailExample(void)

{

CkMailMan mailman;



// This seems to have a 30-day trial period.

bool unlocked = mailman.UnlockComponent("30-day trial");

if (!unlocked)

{

printf("Failed to unlock component\n");

return;

}



mailman.put_SmtpHost("mail.earthlink.net");



This contains the actual email componets

CkEmail email;

email.put_Body("This is a test\r\nThis is line #2");

email.AddTo("Google Hacks","communityonwer@gmail.com");

email.put_FromAddress("communityonwer@gmail.com");

email.put_Subject("Google Hacks is the best site");



if (!mailman.SendEmail(&email))

{

mailman.SaveLastError("errors.xml"); // error

}

}



int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

freopen("stdout.txt","w",stdout);

EmailExample();

CkSettings::cleanupMemory();

_CrtDumpMemoryLeaks();

return 0;

}





If you want html just replace body with a html code. Only basic html code will work.



If you wish to add BCC after email.AddTo() . You need to add this as many as times as you want based to how many people

you want to mail.

email.AddBcc("Orkut Tricks","communityonwer@gmail.com");



If you wish to add CC just copy the above code and replace Bcc with cc



Code to add attachments . Repete this code as many times as you want based on the no of attachments you want to send

// Add a file attachment.

if (!email.AddFileAttachment("googlehacks.gif",0))

{

email.SaveLastError("errors.xml");

return;

}





If you want all your attachments to be zipped the use this code after you enter all the attachments



if (!email.ZipAttachments("googlehacks.zip"))

{

email.SaveLastError("errors.xml");

return;

}

No comments:

Post a Comment