Manage Attachments in Email Message in Ruby

Aspose.Email - Manage Attachments in Email Message

To Add Attachments to a New Email Message using Aspose.Email Java for Ruby, call add_attachments method of ManageAttachments module. Here you can see example code.

Ruby Code

 def add_attachments()

    data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'

    # Create a new instance of MailMessage class

    message = Rjb::import('').new

    # Set subject of the message

    message.setSubject("New message created by Aspose.Email for Java")

    mail_address = Rjb::import('')

    # Set Html body

    message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +

            "<font color=blue>This line is in blue color</font>")

    # Set sender information

    message.setFrom("", "Sender Name", false))

    # Add TO recipients

    message.getTo().add("", "Recipient 1", false))

    # Adding attachment

    # Load an attachment

    attachment = Rjb::import('').new(data_dir + "attachment.txt")

    # Add attachment in instance of MailMessage class


    # Save message to disc + "Add-Attachment.msg", Rjb::import('').getMsg())

    # Display Status

    puts "Added attachment successfully."


Download Running Code

Download Manage Attachments in Email Message (Aspose.Email) from any of the below mentioned social coding sites: