I am working on a Mail App in VB.NET. The mail app sends mail in two steps :
1.It converts the Email body(rtf) to HTML
2.Then it sends the converted HTML as the email body
For these, i am using EASendMail(to send email),Itenso RTF2HTML converter(to convert RTF to HTML). Now my email body is basically a RichTextBox(bodytxt.text).The code used are :
Imports Itenso.Rtf.Converter.Html
Imports EASendMail
Imports Itenso.Rtf.Support
Imports Itenso.Rtf
Dim rr As String = bodytxt.Rtf.Replace("\0", "")
Dim rtfDocument As IRtfDocument = RtfInterpreterTool.BuildDoc(rr)
Dim htmlConverter As New RtfHtmlConverter(rtfDocument)
Dim html1 As String = htmlConverter.Convert()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New EASendMail.SmtpClient()
oMail.From = fromtxt.Text
oMail.To = New AddressCollection(totxt.Text)
oMail.Subject = subjecttxt.Text
oMail.HtmlBody = html1
Dim oServer As New SmtpServer(MailConfig.host.Text)
oServer.Port = MailConfig.port.Text
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
oServer.User = fromtxt.Text
oServer.Password = MailConfig.password.Text
Dim r As Integer
If ListBox1.Items.Count <= 0 Then
Else
oMail.AddAttachment(ListBox1.Items(r))
End If
oSmtp.LogFileName = Application.StartupPath & "\maillog.OFPTX"
oSmtp.SendMail(oServer, oMail)
Now this code works fine and sends the email as HTML-maintaining all text formatting . The problem is, suppose i add an image in the rich textbox, then the image is sent but it can't be opened/viewed from my mail client's inbox.In Gmail, It shows as a broken image and "Open image in new tab" show "We can't display this image"...
1.What am i doing wrong ?How to send the image not as an attachment but a part of the email body ?
2.Can my code be improved ?