EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Help me with mail attachement

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#12617
Posted: 02/26/2010 13:20:21
by Levan Sopromadze (Basic support level)
Joined: 02/16/2010
Posts: 5

Hi All,

I need help with attachment in mail. I wrote code witch is sending mail successful, but I can't understand how can I add file as attachment and send this mail with SecureBlackBox.

This is my sample code:

Code
SBSimpleMIME.TElSimpleMIMEMessage mailMessage = new SBSimpleMIME.TElSimpleMIMEMessage();
SBSMTPClient.TElSMTPClient smtpClient = new SBSMTPClient.TElSMTPClient();
SBSimpleMIME.TElSimpleMIMEAttachment attachement = new SBSimpleMIME.TElSimpleMIMEAttachment();

smtpClient.Address = "xxx";
smtpClient.Username = "xxx@xxx.xxx";
smtpClient.Password = "xxxxxxxxxxx";
smtpClient.Port = 25;

mailMessage.Subject = "Test Message";
mailMessage.From = "le1@mail.ru";
mailMessage.To_.Add("levan@itdc.ge");
mailMessage.BodyPlain.Text = "Message Body :)";
mailMessage.AddAttachment();            
attachement.AttachFile(filename);            
            
try
{
   smtpClient.Open();
   smtpClient.Login("");
   smtpClient.Send(mailMessage);
   MessageBox.Show("Sent");
}
catch (Exception ex)
{
   MessageBox.Show("Error:" + ex.ToString());
}
finally
{
   smtpClient.Close(true);                
}

Please help me with adding file as attachement.
Thanks
#12620
Posted: 02/26/2010 13:56:03
by Eugene Mayevski (EldoS Corp.)

Should be something like this:

int idx = mailMessage.AddAttachment();
if (idx != -1)
{
TElSimpleMIMEAttachment attach = mailMessage.get_Attachments(idx);
attach.Stream = new FileStream(path_to_filename, FileMode.Open);
attach.ContentType = "application/octet-stream";
attach.Name = filename; // just set some file name to the file
}


Sincerely yours
Eugene Mayevski
#12623
Posted: 02/26/2010 16:27:58
by Levan Sopromadze (Basic support level)
Joined: 02/16/2010
Posts: 5

Thank you, everything is working now

Reply

Statistics

Topic viewed 1369 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!