Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
695
How to send a column in ultragrid as attachment in outlook
posted

I have an ultragrid which has several columns.There is one column named CERTIFICATE which contains jpg,pdf..etc type of files.My requirement is that if i select a particular row and click button "btnemail" i want that particular  row's column CERTIFICATE  to be shown as attachment in outlook.Can any  one plz help me out

  • 53790
    posted

    Hello MauryaIsha,

    Last year I made something similar in one of my projects, so maybe you could use this approach below:

            public static bool SendMail(string MailAddressTo, string MailMessage, string AttachedFileName)

            {

                Attachment AttFile = null;

                string OriginalMailAddressTo = MailAddressTo;

                try

                {

                    SmtpClient smtpClient = new SmtpClient();

                    MailMessage message = new MailMessage();

                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                    smtpClient.Host = Properties.Settings.Default.MailServer;

                    smtpClient.UseDefaultCredentials = Properties.Settings.Default.MailCredentials;

                    if (!Properties.Settings.Default.MailCredentials) smtpClient.Credentials = new NetworkCredential(Properties.Settings.Default.MailUsername, Properties.Settings.Default.MailPassword);

     

                    MailAddress MailAddressFrom = new MailAddress(Properties.Settings.Default.MailAddress);

                    message.From = MailAddressFrom;

     

                    // Цикъл по адресите до които ще се изпраща e-mail ако са повече от един разделени с ";"

                    while (MailAddressTo.Length > 0)

                    {

                        int charIndex = MailAddressTo.IndexOf(';');

                        if (charIndex == -1)

                        {

                            try

                            {

                                message.To.Add(MailAddressTo);

                                break;

                            }

                            catch (Exception ex)

                            {

                                EventLog.WriteEntry(ImsDataExchangeService.sSource, "Incorrect e-mail address <" + MailAddressTo + "> " + ex.ToString(), EventLogEntryType.Warning);

                            }

                        }

                        else

                        {

                            string currentAddress = MailAddressTo.Substring(0, MailAddressTo.IndexOf(';'));

                            try

                            {

                                message.To.Add(currentAddress);

                            }

                            catch (Exception ex)

                            {

                                EventLog.WriteEntry(ImsDataExchangeService.sSource, "Incorrect e-mail address <" + currentAddress + "> " + ex.ToString(), EventLogEntryType.Warning);

                            }

                            MailAddressTo = MailAddressTo.Remove(0, charIndex + 1);

                        }

     

                    }

                    message.Subject = Properties.Settings.Default.MailSubject;

                    message.IsBodyHtml = false;

                    message.Body = MailMessage;

     

                    if (AttachedFileName != null)

                    {

                        AttFile = new Attachment(AttachedFileName);

                        message.Attachments.Add(AttFile);

                    }

                    smtpClient.Send(message);

                    if (AttachedFileName != null) AttFile.Dispose();

                    return true;

                }

                catch (Exception ex)

                {

                    EventLog.WriteEntry(ImsDataExchangeService.sSource, "GENERAL ERROR: It is not possible to send the message to " + OriginalMailAddressTo + ". " + ex.ToString(), EventLogEntryType.Warning);

                    return false;

                }

            }

    When you press your Button you should call this method. Please provide information about recipient, message and file that will be attached to this e-mail. The attachment (whole e-mail) will be visible in Sent Items folder of your account.

    Please let me know if you have any questions