代表者の戯言

Auto sending E-mail(not through excel)




This is the way to send an Email not through Excel.

It is effective to have the LIST before using this program.



Dim list As New List(Of String)

'------------------------------------------
'mail address:tx1
'mail cc:tx2
'mail BCC:tx3
'the place of attachment file:tx4
'Mail tytle:tx5
'Mail content:tx6
'------------------------------------------
Dim tx1 As String = ""

list.Add(mailaddress)
list.Add("")
list.Add("xxx@xxx.co.jp")
list.Add("")
list.Add("tytle")
list.Add("content")


'------------------------------------------------------
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Interop

Public Class email


Public Sub nonauto(ByVal List1 As List(Of String))

Dim tx2 As String = ""
Dim tx3 As String = ""
Dim tx4 As String = ""
Dim tx5 As String = ""
Dim tx6 As String = ""


tx1 = List1(0)
tx2 = List1(1)
tx3 = List1(2)
tx4 = List1(3)
tx5 = List1(4)
tx6 = List1(5)

Try
' ● Outlook( no-show)
Dim olApp As New Outlook.Application
Dim olNs As Outlook.NameSpace = olApp.GetNamespace("MAPI")
olNs.Logon("", "", False, False)

' ● making mail
Dim mail As Outlook.MailItem
mail = CType(olApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)

' ● setting
mail.To = tx1
mail.CC = tx2
mail.BCC = tx3

' ● attachment file
If System.IO.File.Exists(tx4) Then
mail.Attachments.Add(tx4)
Else
End If
mail.Subject = tx5
mail.Body = tx6

mail.Display()
Catch ex As Exception
MessageBox.Show("error: " & ex.Message)
End Try


End Sub

sending mail