Download AddEmail 3.0 User Manual

Transcript
15
AddEmail 3.0 User Manual
2.3
C#
2.3.1
Using AddEmail in C# projects
To use AddEmail in your C# project perform the following steps:
1. Add a reference to the AddEmail library: In Visual Studio main menu, select View -> Solution
Explorer to open Solution Explorer. Right-click on the project that will use AddEmail and select Add
Reference from the pop-up menu. Click COM tab, find and select AddEmail 3.0 Type Library, click
Select button then OK button.
2. Declare variable that will hold a reference to the SmtpMail object:
private AddEmailLib.SmtpMailClass objSmtpMail;
3. Create an instance of the SmtpMail object in the constructor of your class:
objSmtpMail = new AddEmailLib.SmtpMailClass();
4. Set SMTP server address, port, username and password:
objSmtpMail.SmtpServer = "mail.myserver.com";
objSmtpMail.SmtpPort = 25;
objSmtpMail.SmtpUsername = "jsmith";
objSmtpMail.SmtpPassword = "mypassword";
5a. Send an e-mail synchronously using SimpleSend or SimpleSendAttachment:
string strError;
int resultCode = objSmtpMail.SimpleSend("[email protected]",
"[email protected];[email protected]", "test", "Test message", out strError);
if (resultCode == 0)
{
// E-mail was sent successfully
}
else
{
// Send failed, strError contains detailed error description
}
5b. Alternatively, create and fill MailMessage object and send it synchronously using Send or
asynchronously using SendAsync:
// Create message and setup subject and body
MailMessageClass objMessage = new AddEmailLib.MailMessageClass();
objMessage.MessageSubject = "test";
objMessage.MessageBody = "Test message";
// Setup sender
MailAddressClass objSender = new MailAddressClass();
objSender.Address = "[email protected]";
objSender.Name = "Jane Smith";
objMessage.Sender = objSender;
// Setup first recipient
MailAddressClass objRecipient = new MailAddressClass();
objRecipient.Address = "[email protected]";
objRecipient.Name = "Jane Smith";
objMessage.AddRecipient(objRecipient);
Copyright (c) 2004-2010 Traysoft Inc. All rights reserved.