Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET SMTP

 AfterLogic Forum : MailBee.NET SMTP
Subject Topic: Saving the mail Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
ay1585
Newbie
Newbie
Avatar

Joined: 01 April 2009
Location: India
Online Status: Offline
Posts: 7
Posted: 01 April 2009 at 1:54am | IP Logged Quote ay1585

I am sending a mail using SMTP. I want to save the mail,including the details like To,Cc,Bcc,Subject,Body and also the attachment path(if any attachment exists) in to a database table,using a unique id. How to make this possible?
Back to Top View ay1585's Profile Search for other posts by ay1585
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 01 April 2009 at 4:00am | IP Logged Quote Andrew

You can save a message into a database as follows (in C# syntax):

Code:
// Create message object or replace this code with receiving message from POP3/IMAP server
MailMessage msg = new MailMessage();

// Create connection with the database
string myConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\messages.mdb;User Id=admin;Password=;";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
try
{
     myConnection.Open();

     // Insert raw message data into the database
     string commandString = @"INSERT INTO messages_table (uid, raw_data) VALUES ( @uid, @raw_data )";
     OleDbCommand cmd = new OleDbCommand(commandString, myConnection);

     cmd.Parameters.Add("@uid", msg.UidOnServer);
     cmd.Parameters.Add("@raw_data" , msg.GetMessageRawData());

     cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
     myConnection.Close();
}


Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
ay1585
Newbie
Newbie
Avatar

Joined: 01 April 2009
Location: India
Online Status: Offline
Posts: 7
Posted: 01 April 2009 at 6:39am | IP Logged Quote ay1585

I Thank you for your reply. I am trying to work on the code which you have suggested. How ever,I have few queries. First of all,I am sending a mail. I want this sent mail to be saved in my SQLServer Database table for my future reference. This mail should be saved in my Send click itself. So, that based on the "To" recepient address, I may need to send a remainder in future. This is the requirement. Can you please suggest on this?
Back to Top View ay1585's Profile Search for other posts by ay1585
 
Andrew
AfterLogic Support
AfterLogic Support


Joined: 28 April 2006
Location: United States
Online Status: Offline
Posts: 1189
Posted: 01 April 2009 at 6:48am | IP Logged Quote Andrew

To save message after or before sending, you should replace msg.GetMessageRawData() with mailer.Message.GetMessageRawData() where "mailer" is an instance of Smtp class used for sending the message.

Best regards,
Andrew
Back to Top View Andrew's Profile Search for other posts by Andrew
 
ay1585
Newbie
Newbie
Avatar

Joined: 01 April 2009
Location: India
Online Status: Offline
Posts: 7
Posted: 01 April 2009 at 6:48am | IP Logged Quote ay1585

ay1585 wrote:
I Thank you for your reply. I am trying to work on the code which you have suggested. How ever,I have few queries. First of all,I am sending a mail. I want this sent mail to be saved in my SQLServer Database table for my future reference. This mail should be saved in my Send click itself. So, that based on the "To" recepient address, I may need to send a remainder in future. This is the requirement. Can you please suggest on this?


I also have to create my database table accordingly.
For your reference,this is the code that I have used:
    objSmtp = new Smtp();
                objSmtp.From.AsString = "my mail address";
                objSmtp.To.AsString = txtReceiver.Text;
                objSmtp.Cc.AsString = txtCc.Text;
                objSmtp.Bcc.AsString = txtBcc.Text;
                objSmtp.Subject = txtSubject.Text;                
                objSmtp.Message.BodyHtmlText = Editor.Text;
                objSmtp.SmtpServers.Add("my host name", "user name", "password");
                objSmtp.DnsServers.Autodetect();                
                objSmtp.Connect();
                objSmtp.Message.Attachments.Add(FileUpload1.PostedFile.FileN ame);
                objSmtp.Send();
                objSmtp.Disconnect();                
               
Back to Top View ay1585's Profile Search for other posts by ay1585
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide