邮件组件集合MailBee Objects发送电子邮件教程(三):附件的添加

本示例将会展示发送带有2个附件的纯文本电子邮件的操作。第一个附件以其自然名称放入邮件中。第二个附件以不同的名称放置(从临时文件添加附件时经常使用)。

MailBee Objects是一个组件集合。您可以使用该控件创建并将邮件发送到SMTP服务器并从POP3服务器接收、解析以及删除电子邮件,还能在IMAP4服务器上管理电子邮件以及文件夹。它同样支持SSL以及S/MIME以获得更好的安全性能。MailBee控件能在ASP、VB、C++或任何支持ActiveX技术的语言中使用。

最新版MailBee Objects


本示例将会展示发送带有2个附件的纯文本电子邮件的操作。第一个附件以其自然名称放入邮件中。第二个附件以不同的名称放置(从临时文件添加附件时经常使用)

SMTP.AddAttachment是示例的关键属性。为简单起见,不使用SMTP身份验证,并且不执行错误检查。

Visual Basic

Dim objSMTP' Create mailer componentSet objSMTP = CreateObject("MailBee.SMTP")' Unlock SMTP componentobjSMTP.LicenseKey = "put your license key here"' Set SMTP server nameobjSMTP.ServerName = "mail.server.com"' Set message propertiesobjSMTP.FromAddr = "me@mydomain.com"objSMTP.ToAddr = "you@yourdomain.com"objSMTP.Subject = "Hi"objSMTP.BodyText = "This is test message with attachments"' Add attachment from "file1.doc" file.' It will appear as "file1.doc" in the e-mail.objSMTP.AddAttachment "C:filesfile1.doc"' Add attachment from "file2.tmp" file.' It will appear as "renamed.doc" in the e-mail.objSMTP.AddAttachment "C:filesfile2.tmp", , ,"renamed.doc"' Send it!objSMTP.Send

ASP:

<% Dim objSMTP ' Create mailer component Set objSMTP = Server.CreateObject("MailBee.SMTP") ' Unlock SMTP component objSMTP.LicenseKey = "put your license key here" ' Set SMTP server name objSMTP.ServerName = "mail.server.com" ' Set message properties objSMTP.FromAddr = "me@mydomain.com" objSMTP.ToAddr = "you@yourdomain.com" objSMTP.Subject = "Hi" objSMTP.BodyText = "This is test message with attachments" ' Add attachment from "file1.doc" file. ' It will appear as "file1.doc" in the e-mail. objSMTP.AddAttachment "C:filesfile1.doc" ' Add attachment from "file2.tmp" file. ' It will appear as "renamed.doc" in the e-mail. objSMTP.AddAttachment "C:filesfile2.tmp", , ,"renamed.doc" ' Send it! objSMTP.Send %>

发送方式

将邮件发送到SMTP服务器。要从假地址发送,请使用SendEx方法。从组邮件中常用的伪地址发送邮件,以确保退回邮件都到达同一地址。

注意:许多SMTP服务器需要用户身份验证才能发送电子邮件。有关详细信息,请参见AuthMethod属性参考。下面的示例代码使用身份验证。如果服务器不需要或不支持它,请注释相应的行或仅设置AuthMethod = 0。

blnResult = ObjectName.Send

邮件组件集合MailBee Objects发送电子邮件教程(三):附件的添加

使用例子

Dim Mailer'Using visual basic to create objectSet Mailer = CreateObject("MailBee.SMTP")'Using ASP to create object'Set Mailer = Server.CreateObject("MailBee.SMTP")'In ASP use Response.Write instead of MsgBoxMailer.LicenseKey = "put your license key here"Mailer.ServerName = "mail.server.com"' Comment next 3 lines if authentication is not required.Mailer.AuthMethod = 1 ' Using PLAIN authenticationMailer.UserName = "MyUserName" ' Mail account nameMailer.Password = "MyPassword" ' Mail account passwordIf Mailer.Connect Then  Mailer.Message.ToAddr = "bill@yoursite.com"  Mailer.Message.FromAddr = "joe@mysite.com"  Mailer.Message.Subject = "Hello"  Mailer.Message.ImportBodyText "C:docsletter.htm", True  If Not Mailer.Send Then MsgBox Mailer.ErrDesc  Mailer.DisconnectEnd If

以上就是本次教程的全部内容,接下来会有更多相关教程,敬请关注!您也可以在评论留下你的经验和建议除了本教程,想要了解更多电子邮件相关产品信息的可以点击此处查看。有更多教程资源等着你!

==========================================

如果想要购买正版授权MailBee.NET Objects的朋友,可以联系在线客服

关注慧聚IT微信公众号 了解产品的最新动态及最新资讯。

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月12日
下一篇 2020年1月12日

相关推荐

发表回复

登录后才能评论