Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27207

Send html templates via email with Microsoft.Office.Interop.outlook

$
0
0
Hello all,

I need to send templates emails via email throught an html file with embed images.

The html file is created.

The contect apart from the images has two parts, one part is modify by the person in charge to create templates and another part is going to be modify by the person who is going to send the template, in both manners by windows form.

This is an example.

In the body of the template, there are placeholders one from the creator and other for the sender.

[Dear][Name],

[Befor1][inc],[comment][issue]

In this example [Dear],[Befor1] and [comment], will be modify by the creator.
[name] and [inc] by the sender.

After creator modify the template, it will copy on a directory into the local computer.
and then the sender can modify the templates.

This all done and works fine.

My problem now is that I cannot sent the templates by mail, all emails appears blank.

This is the code I am using perhaps someone can help me.

Code:

Dim item As Outlook.MailItem
02                Dim SigString As String
03                Dim Signature As String
04                Dim Body As String = Nothing
05       
06                Dim olAccounts As Outlook.Accounts
07                olApp = New Outlook.Application()
08                olSession = olApp.Session
09                olAccounts = olSession.Accounts
10                'CC1 SPANISH
11                If (tempCB.Text = "Template" Or LanguageCB.Text = "Language") Then
12                    MsgBox("Please, choose a template and language", MsgBoxStyle.OkOnly)
13                ElseIf LanguageCB.Text = "Language Then" Then
14                    MsgBox("Please, choose a language", MsgBoxStyle.OkOnly)
15                ElseIf tempCB.Text = "Template" Then
16                    MsgBox("Please, choose a template", MsgBoxStyle.OkOnly)
17                End If
18       
19               
20                    Dim myStreamReaderL1 As System.IO.StreamReader
21                    Dim myStr As String
22                    Dim path As String = "c:\users\" + Environment.UserName + "\Desktop\CC1SPANISHout.html"
23                   
24       
25       
26                   
27                    myStreamReaderL1 = System.IO.File.OpenText(path)
28                    myStr = myStreamReaderL1.ReadToEnd()
29                    myStreamReaderL1.Close()
30       
31                    'Modifica el archivo en una nueva copia, manteniendo el archivo original
32                    myStr = myStr.Replace("[NAME]", UserTMPTxt.Text)
33                    myStr = myStr.Replace("[NUMINC1]", IncTMPTxt.Text)
34                    myStr = myStr.Replace("[NUMINC2]", IncTMPTxt.Text)
35                    myStr = myStr.Replace("[ISSUE]", IssueTMPTxt.Text)
36       
37                 
38       
39                    If EmailTMPTxt.Text = "" Or IncTMPTxt.Text = "" Then
40                        MsgBox("Email addresss and Incident number is empty", MsgBoxStyle.Exclamation)
41                    ElseIf Not EmailTMPTxt.Text = "" Or IncTMPTxt.Text = "" Then
42                        item = olApp.CreateItem(Outlook.OlItemType.olMailItem)
43                        item.To = EmailTMPTxt.Text
44                        item.BodyFormat = OlBodyFormat.olFormatHTML
45                        item.HTMLBody = myStr
46                        'USING HAS A TEST
47                        item.SentOnBehalfOfName = "jose.rodriguez.an@gmail.com"
48                        'item.SentOnBehalfOfName = "trackin.sd@airbus.com"
49                        item.Subject = "CC1 - Numero de Incidencia " + IncTMPTxt.Text
50                        'item.BodyFormat = MailFormat.mfHTML
51                        'item.Body = Body + vbCr + Signature
52                        item.Send()
53                        MsgBox("Mail has sent")
54                    End If

Thank you,
Jose Luis,

Viewing all articles
Browse latest Browse all 27207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>