RichTextBox- RTF -Send by Email
-
Thursday, May 31, 2007 11:30 PM
Hi all,
I've researched a lot but can't find a solution. I have text in a RichTextBox with RTF format (with an image) that I need to send by email (all in VB.NET 2005).
The code to send email has:
...
With MailMsg.From =
New MailAddress("abc@abc.ab").BodyEncoding = System.Text.Encoding.Default
.Subject = strSubject.Trim()
.Body = strMessage.Trim() & vbCrLf
.Priority = MailPriority.High
.IsBodyHtml =
True End With...
Dim SmtpMail As New SmtpClientSmtpMail.Host = strHost
'SmtpMail.Credentials = theCredentialSmtpMail.Send(MailMsg)
and it actually sends the email but the body of the mail shows RTF garbage like:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}{\f1\froman\fprq2\fcharset0 Times New Roman;}} {\colortbl ;\red0\green128\blue0;} \viewkind4\uc1\pard\nowidctlpar\f0\fs17
Is there any way I can send the .rtf content of the richtextobox via email without using a third-party component nor Word? If I need to use Word, is there any URL that shows how to do this?
Thanks very much for your time,
ST
Answers
-
Wednesday, June 06, 2007 6:08 AM
ST1,
According to your sending RTF problems, I would like to recommend you to use Word content to have a try. I have three suggestions:
1. If you use the Outlook MailItem object to send email, here is a small sample:
Code SnippetDim missing As Object = Missing.Value
' get the Outlook Application Object
Dim outlookApplication As New Outlook.Application()
' get the namespace object
Dim [nameSpace] As Outlook.NameSpace = outlookApplication.GetNamespace("MAPI")
' Logon to Session, here we use an already opened Outlook
[nameSpace].Logon(missing, missing, True, True)
' Create a new EmailItem
Dim mail As Outlook.MailItem = CType(outlookApplication.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
' Set Email, header and Recipient
mail.Subject = "Email with Word Attachment"
mail.Body = "This is a Text"
mail.To = "your.address@yourdomain.com"
' Add Attachments to the Item
mail.Attachments.Add("")
Dim request As Holiday
mail.Send() '
Marshal.ReleaseComObject(mail)
' logoff from namespace
[nameSpace].Logoff()
' release resources
Marshal.ReleaseComObject([nameSpace])
Marshal.ReleaseComObject(outlookApplication.Application)
GC.WaitForPendingFinalizers()
GC.Collect()
2. Send the Word Document without Outlook:
Code SnippetDim message As New System.Net.Mail.MailMessage("me@my.com", "you@your.com", "Word attachment", "I'm sending you my document!")
message.Attachments.Add(New System.Net.Mail.Attachment("c:\word.doc"))
Dim smtp As New System.Net.Mail.SmtpClient(smtp) '
smtp.Send(message)
3. Send the mail in HTML format:
Code Snippet<html>
<head>
<meta name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p
{margin-right:0cm;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle17
{font-family:Arial;
color:windowtext;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
</body>
</html>
All Replies
-
Wednesday, June 06, 2007 6:08 AM
ST1,
According to your sending RTF problems, I would like to recommend you to use Word content to have a try. I have three suggestions:
1. If you use the Outlook MailItem object to send email, here is a small sample:
Code SnippetDim missing As Object = Missing.Value
' get the Outlook Application Object
Dim outlookApplication As New Outlook.Application()
' get the namespace object
Dim [nameSpace] As Outlook.NameSpace = outlookApplication.GetNamespace("MAPI")
' Logon to Session, here we use an already opened Outlook
[nameSpace].Logon(missing, missing, True, True)
' Create a new EmailItem
Dim mail As Outlook.MailItem = CType(outlookApplication.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
' Set Email, header and Recipient
mail.Subject = "Email with Word Attachment"
mail.Body = "This is a Text"
mail.To = "your.address@yourdomain.com"
' Add Attachments to the Item
mail.Attachments.Add("")
Dim request As Holiday
mail.Send() '
Marshal.ReleaseComObject(mail)
' logoff from namespace
[nameSpace].Logoff()
' release resources
Marshal.ReleaseComObject([nameSpace])
Marshal.ReleaseComObject(outlookApplication.Application)
GC.WaitForPendingFinalizers()
GC.Collect()
2. Send the Word Document without Outlook:
Code SnippetDim message As New System.Net.Mail.MailMessage("me@my.com", "you@your.com", "Word attachment", "I'm sending you my document!")
message.Attachments.Add(New System.Net.Mail.Attachment("c:\word.doc"))
Dim smtp As New System.Net.Mail.SmtpClient(smtp) '
smtp.Send(message)
3. Send the mail in HTML format:
Code Snippet<html>
<head>
<meta name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
p
{margin-right:0cm;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman";}
span.EmailStyle17
{font-family:Arial;
color:windowtext;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> </span></font></p>
</div>
</body>
</html>
-
Sunday, March 25, 2012 7:30 PMhow can we send rtf with embedded image in email using outlook object in asp .net?
Guneet Kalra

