vb.net 2005 outlook发送邮件 附件 发送箱
2009-11-04 13:06
337 查看
我新写了一个用mapi发邮件的例子,大家一起参考
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose()
'MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
MAPIMessages1.AttachmentPathName = "c:/file.txt"
MAPIMessages1.Send()
MAPIMessages1.Send(True)
MAPISession1.SignOff()
这个是用MAPI写的.可以弹出outlook express窗口.并可加附件的.点发送就出去了.
但是前提是,要加进去MAPI的com组件.
地址我提供给大家
http://www.vector.co.jp/soft/dl/win95/util/se342080.html
是一个日本网站.下载之后运行.之后MAPI这个组件就出现了.因为我们用的VB.NET都是express版的,组件不全的原因.
这个做过之后.还不行,出错说MAPI没有在注册表里注册. 下载msmapi32.ocx
文件.放在C:/WINDOWS里面和system32里面,具体放在哪里好用我不太清楚.总之都放了.
在dos窗口运行 regsvr32 c:/C:/WINDOWS/msmapi32.ocx c:/C:/WINDOWS/system32/msmapi32.ocx
再运行上面的代码,就没有问题了.
相信这个做完了,可以解决大家的许多问题.
下面的是直接发送到送信箱的代码,差不太多,但是有点细节需要主意.
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
'MAPIMessages1.Compose()
MAPIMessages1.MsgIndex = -1 '这个地方的compose去掉.改为这个
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
MAPIMessages1.AttachmentPathName = "c:/file.txt"
MAPIMessages1.Send(false)'true改为false
MAPISession1.SignOff()
改完之后,还是会出一个小的对话框问要不要发送.这个在工具-->设置里面-->安全里面把别人的应用用自己的名字送信这一项cancel就ok了.
完成了..
除了 mapi 用sysstem.Net.Mail.MailMessage也可以发
为了我以后参考用一并写在下面
Dim msg As New System.Net.Mail.MailMessage()
msg.From = New System.Net.Mail.MailAddress("tiang@icc.com")
msg.To.Add(New System.Net.Mail.MailAddress("liuyy@icc.com"))
msg.CC.Add(New System.Net.Mail.MailAddress("tiang@icc.com"))
'件名
msg.Subject = "Subject "
'本文
msg.Body = "Body "
msg.Priority = System.Net.Mail.MailPriority.High
msg.DeliveryNotificationOptions = _
System.Net.Mail.DeliveryNotificationOptions.Delay Or _
System.Net.Mail.DeliveryNotificationOptions.OnFailure Or _
System.Net.Mail.DeliveryNotificationOptions.OnSuccess
Dim attach1 As New System.Net.Mail.Attachment("C:/file.txt")
msg.Attachments.Add(attach1)
Dim attach2 As New System.Net.Mail.Attachment("C:/file1.gif")
msg.Attachments.Add(attach2)
Dim sc As New SmtpClient()
sc.Host = "icc.com"
'送信
sc.Send(msg)
msg.Dispose()
这个也可以直接发送出去.以上就是这几天的研究成果,希望对vb.net做邮件的人有帮助.
以上
以下是office microsoft outlook发送邮件的全部方法.复数附件可
赋值代码运行可. 前提条件是参照里面的outlook com组件要添加上
----------------------------office outlook ↓ 直接送信複数可
Dim Oa
Dim Item
'Dim DestFldr As Outlook.MAPIFolder
Oa = CreateObject("Outlook.Application")
Item = Oa.CreateItem(0)
'Item.Compose()
' DestFldr = Item.GetNamespace("MAPI")
Item.To = "tiang@icc.co.jp"
Item.Subject = "hello"
Item.Body = "hello"
Item.Attachments.add("C:/file.txt")
Item.Attachments.add("C:/file1.gif")
Item.Send()
-----------------------------------office outlook ↓ 启动邮件的界面后发送.複数可
Dim oApp As Outlook._Application
oApp = New Outlook.Application()
Dim mailItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
mailItem.Subject = "This is the subject"
mailItem.To = "tiang@icc.co.jp"
mailItem.Body = "This is the message."
mailItem.CC = "aaaaa"
Dim sSource As String = "C:/file.txt"
Dim sSource1 As String = "C:/file1.gif"
Dim sDisplayName As String = "Hello.txt"
Dim sDisplayName1 As String = "Hello.txt"
Dim sBodyLen1 As String = mailItem.Body.Length
Dim oAttachs1 As Outlook.Attachments = mailItem.Attachments
Dim oAttach1 As Outlook.Attachment
oAttach1 = oAttachs1.Add(sSource, , sBodyLen1 + 1)
oAttach1 = oAttachs1.Add(sSource1, , sBodyLen1 + 1)
mailItem.Importance = Outlook.OlImportance.olImportanceLow
mailItem.Display(False)
--------------------office outlook ↑
追加 复数个附件添加方法. 这个是outlook express的方法
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
Dim filepath(1) As String
filepath(0) = "c:/file1.gif"
filepath(1) = "c:/file.txt"
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
'MAPIMessages1.Compose()
MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
'MAPIMessages1.AttachmentPathName = "c:/file.txt"
For i As Integer = 0 To filepath.Length - 1
MAPIMessages1.AttachmentIndex = i
MAPIMessages1.AttachmentPathName = filepath(i)
Next i
'MAPIMessages1.AttachmentCount = "c:/file1.gif"
'MAPIMessages1.Send(True)
MAPIMessages1.Send(False)
MAPISession1.SignOff()
直接运行可.前提可以参照最上面的讲解.
这里面分直接发送和先起画面再发送两种
上面的是直接发送的.要变成先启动画面再发送
'MAPIMessages1.Compose() 把这句的注释打开
MAPIMessages1.MsgIndex = -1注释掉这句
'MAPIMessages1.Send(True)把这句的注释打开
MAPIMessages1.Send(False)注释掉这句
就变成先启动画面点发送的了.
以上就是全套的vb.net邮件发送的全部了.复制可直接运行.
变态的头儿的要求,1个多星期的研究成果大家分享
先祝大家好运了
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose()
'MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
MAPIMessages1.AttachmentPathName = "c:/file.txt"
MAPIMessages1.Send()
MAPIMessages1.Send(True)
MAPISession1.SignOff()
这个是用MAPI写的.可以弹出outlook express窗口.并可加附件的.点发送就出去了.
但是前提是,要加进去MAPI的com组件.
地址我提供给大家
http://www.vector.co.jp/soft/dl/win95/util/se342080.html
是一个日本网站.下载之后运行.之后MAPI这个组件就出现了.因为我们用的VB.NET都是express版的,组件不全的原因.
这个做过之后.还不行,出错说MAPI没有在注册表里注册. 下载msmapi32.ocx
文件.放在C:/WINDOWS里面和system32里面,具体放在哪里好用我不太清楚.总之都放了.
在dos窗口运行 regsvr32 c:/C:/WINDOWS/msmapi32.ocx c:/C:/WINDOWS/system32/msmapi32.ocx
再运行上面的代码,就没有问题了.
相信这个做完了,可以解决大家的许多问题.
下面的是直接发送到送信箱的代码,差不太多,但是有点细节需要主意.
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
'MAPIMessages1.Compose()
MAPIMessages1.MsgIndex = -1 '这个地方的compose去掉.改为这个
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
MAPIMessages1.AttachmentPathName = "c:/file.txt"
MAPIMessages1.Send(false)'true改为false
MAPISession1.SignOff()
改完之后,还是会出一个小的对话框问要不要发送.这个在工具-->设置里面-->安全里面把别人的应用用自己的名字送信这一项cancel就ok了.
完成了..
除了 mapi 用sysstem.Net.Mail.MailMessage也可以发
为了我以后参考用一并写在下面
Dim msg As New System.Net.Mail.MailMessage()
msg.From = New System.Net.Mail.MailAddress("tiang@icc.com")
msg.To.Add(New System.Net.Mail.MailAddress("liuyy@icc.com"))
msg.CC.Add(New System.Net.Mail.MailAddress("tiang@icc.com"))
'件名
msg.Subject = "Subject "
'本文
msg.Body = "Body "
msg.Priority = System.Net.Mail.MailPriority.High
msg.DeliveryNotificationOptions = _
System.Net.Mail.DeliveryNotificationOptions.Delay Or _
System.Net.Mail.DeliveryNotificationOptions.OnFailure Or _
System.Net.Mail.DeliveryNotificationOptions.OnSuccess
Dim attach1 As New System.Net.Mail.Attachment("C:/file.txt")
msg.Attachments.Add(attach1)
Dim attach2 As New System.Net.Mail.Attachment("C:/file1.gif")
msg.Attachments.Add(attach2)
Dim sc As New SmtpClient()
sc.Host = "icc.com"
'送信
sc.Send(msg)
msg.Dispose()
这个也可以直接发送出去.以上就是这几天的研究成果,希望对vb.net做邮件的人有帮助.
以上
以下是office microsoft outlook发送邮件的全部方法.复数附件可
赋值代码运行可. 前提条件是参照里面的outlook com组件要添加上
----------------------------office outlook ↓ 直接送信複数可
Dim Oa
Dim Item
'Dim DestFldr As Outlook.MAPIFolder
Oa = CreateObject("Outlook.Application")
Item = Oa.CreateItem(0)
'Item.Compose()
' DestFldr = Item.GetNamespace("MAPI")
Item.To = "tiang@icc.co.jp"
Item.Subject = "hello"
Item.Body = "hello"
Item.Attachments.add("C:/file.txt")
Item.Attachments.add("C:/file1.gif")
Item.Send()
-----------------------------------office outlook ↓ 启动邮件的界面后发送.複数可
Dim oApp As Outlook._Application
oApp = New Outlook.Application()
Dim mailItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)
mailItem.Subject = "This is the subject"
mailItem.To = "tiang@icc.co.jp"
mailItem.Body = "This is the message."
mailItem.CC = "aaaaa"
Dim sSource As String = "C:/file.txt"
Dim sSource1 As String = "C:/file1.gif"
Dim sDisplayName As String = "Hello.txt"
Dim sDisplayName1 As String = "Hello.txt"
Dim sBodyLen1 As String = mailItem.Body.Length
Dim oAttachs1 As Outlook.Attachments = mailItem.Attachments
Dim oAttach1 As Outlook.Attachment
oAttach1 = oAttachs1.Add(sSource, , sBodyLen1 + 1)
oAttach1 = oAttachs1.Add(sSource1, , sBodyLen1 + 1)
mailItem.Importance = Outlook.OlImportance.olImportanceLow
mailItem.Display(False)
--------------------office outlook ↑
追加 复数个附件添加方法. 这个是outlook express的方法
Dim MAPISession1 As New MSMAPI.MAPISession
Dim MAPIMessages1 As New MSMAPI.MAPIMessages
Dim filepath(1) As String
filepath(0) = "c:/file1.gif"
filepath(1) = "c:/file.txt"
MAPISession1.SignOn()
MAPIMessages1.SessionID = MAPISession1.SessionID
'MAPIMessages1.Compose()
MAPIMessages1.MsgIndex = -1
MAPIMessages1.RecipAddress = "tiang@icc.co.jp"
MAPIMessages1.MsgSubject = "Love your site"
MAPIMessages1.MsgNoteText = "Your MAPI tutorial is great."
'MAPIMessages1.AttachmentPathName = "c:/file.txt"
For i As Integer = 0 To filepath.Length - 1
MAPIMessages1.AttachmentIndex = i
MAPIMessages1.AttachmentPathName = filepath(i)
Next i
'MAPIMessages1.AttachmentCount = "c:/file1.gif"
'MAPIMessages1.Send(True)
MAPIMessages1.Send(False)
MAPISession1.SignOff()
直接运行可.前提可以参照最上面的讲解.
这里面分直接发送和先起画面再发送两种
上面的是直接发送的.要变成先启动画面再发送
'MAPIMessages1.Compose() 把这句的注释打开
MAPIMessages1.MsgIndex = -1注释掉这句
'MAPIMessages1.Send(True)把这句的注释打开
MAPIMessages1.Send(False)注释掉这句
就变成先启动画面点发送的了.
以上就是全套的vb.net邮件发送的全部了.复制可直接运行.
变态的头儿的要求,1个多星期的研究成果大家分享
先祝大家好运了
相关文章推荐
- vb.net连接Outlook发送邮件(亲自实践)
- asp.net 带附件发送邮件
- asp.net 发送邮件,带附件
- c#.net 下的邮件发送(含附件)
- 如何阻止通过Outlook用户发送带Winmail.dat文件附件的邮件
- ASP.NET 实现发送邮件 + 多个收件人 + 多个附件
- vs.net 2003 和2005中邮件发送比较
- VB.net 调用OutLook发邮件(程序自动添加附件)
- 使用System.Net.Mail发送邮件时,附件如果是中文名的处理办法
- 【Vegas原创】ASP.NET读取Excel,并以邮件正文方式和附件方式发送实例
- c#.net 下的邮件发送(含附件)
- asp.net 带附件发送邮件
- ASP.NET 利用Outlook发送邮件
- 一段VB.NET代码,生成邮件,发送邮件,支持SMTP验证用户名密码.
- ASP.NET用QQ,网易发送邮件以及添加附件
- asp.net 验证码 及发送带附件邮件 (完整demo)
- VB.net学习笔记之发送邮件:System.Net.Mail
- c#net中发送带附件的邮件:
- ASP.NET打开Outlook客户端发送邮件
- vb.net发送邮件