MailBee.NET Objects发送电子邮件(SMTP)教程五:发送带有嵌入图片的网页和HTML邮件

本文主要介绍了MailBee.NET Objects中发送发送带有嵌入对象的电子邮件的代码示例。欢迎您下载试用版进行运用!

MailBee.NET Objects介绍和试用点击查看>>> 为了发送带有嵌入对象的电子邮件,开发人员应该使用SMTP object。首先,开发人员应该按照【MailBee.NET Objects发送电子邮件(SMTP)教程一】中所述指定SMTP对象的所有必要属性。 如果HTML格式的邮件没有任何嵌入对象,开发人员可以使用SMTP.BodyHtmlText属性或SMTP.Message.LoadBodyText方法来设置邮件正文。 SMTP.BodyHtmlText属性允许开发人员直接分配邮件正文,如下所示:

C#:
oMailer.BodyHtmlText = @”<DIV>Test HTML message.</DIV><BR><BR>
        <FONT face=””Arial Black”” color=#0000ff size=5>
        <P align=left><STRONG><U>
        This is a test HTML mes-sage.
        </U></STRONG></P></FONT><p>
        <hr size=1>
        <a href=””http://www.afterlogic.com””>www.afterlogic.com</a>”;     
VB.NET:
oMailer.BodyHtmlText = “<DIV>Test HTML message.</DIV><BR><BR>” & vbCrLf & _
        “<FONT face= “”Arial Black”” color = #0000ff size = 5>” & vbCrLf & _
        “<P align=left><STRONG><U>” & vbCrLf & _
        “This is a test HTML mes-sage.” & vbCrLf & _
        “</U></STRONG></P></FONT><p>” & vbCrLf & _
        “<hr size= 1>” & vbCrLf & _
        “<a href= “”http://www.afterlogic.com””>www.afterlogic.com</a>”

 也可以使用SMTP.Message.LoadBodyText方法。在这种情况下,开发人员可以从指定的URI中加载消息,如下所示:

C#:
oMailer.Message.LoadBodyText(@”http://www.domain.com/index.htm”, MessageBodyType.Html);  
VB.NET:
oMailer.Message.LoadBodyText(“http://www.domain.com/index.htm”, MessageBodyType.Html)

 或者

C#:
oMailer.Message.LoadBodyText(@”C:Tempsaved_web_page.htm”, MessageBodyType.Html);     
VB.NET:
oMailer.Message.LoadBodyText(“C:Tempsaved_web_page.htm”, MessageBodyType.Html)

否则,开发人员应该调用SMTP.Message.LoadBodyText方法来编写一个包含嵌入对象(图像,音频或视频)的消息。以下示例将邮件正文加载为默认编码以及指定URI中的所有相关文件:

C#:
oMailer.Message.LoadBodyText(@”http://www.domain.com/index.htm “, 
                MessageBodyType.Html,
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles|
                ImportBodyOptions.ImportRelatedFilesFromUris);       
VB.NET:
oMailer.Message.LoadBodyText(“http://www.domain.com/index.htm “, _
                MessageBodyType.Html, _
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles Or _
                ImportBodyOptions.ImportRelatedFilesFromUris)

 请注意:在使用SMTP.Message.LoadBodyText方法时,所有相关文件将被添加到邮件中。 代码示例:该示例从拥有嵌入对象的现有网页中创建新邮件并发送。在使用MailBee.NET Objects之前,请确保它已解锁。

C#:using System;
using System.Text;
using MailBee;
using MailBee.SmtpMail;
using MailBee.Mime;
namespace EmailApp
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            Smtp oMailer = new Smtp();
            oMailer.To.AddFromString(“Bill Smith <b.smith@domain.com>”);            oMailer.From.AsString = “John Doe <j.doe@domain.com> (Company Info)”;            oMailer.Subject = “Test web page”;            oMailer.Message.LoadBodyText(@”http://www.domain.com/index.htm”, MessageBodyType.Html, Encoding.Default, ImportBodyOptions.ImportRelatedFiles | ImportBodyOptions.ImportRelatedFilesFromUris);            try
            {
                oMailer.Send();
                Console.WriteLine(“The message has been successfully sent.”);
            }
            catch (MailBeeSmtpMessageSizeOutOfRangeException e)
            {
                Console.WriteLine(“The message is too large (more than ” + e.MaxAllowedMessageSize + ” bytes).”);
            }
        }
    }
}
VB.NET:Imports System
Imports System.Text
Imports MailBee
Imports MailBee.SmtpMail
Imports MailBee.Mime
 
Namespace EmailApp
    Class Class1
        <STAThread> _ 
        Shared  Sub Main(ByVal args() As String)
            Dim oMailer As Smtp =  New Smtp() 
 
            oMailer.To.AddFromString(“Bill Smith <b.smith@domain.com>”)
 
            oMailer.From.AsString = “John Doe <j.doe@domain.com> (Company Info)”
 
            oMailer.Subject = “Test web page”
 
            oMailer.Message.LoadBodyText(“http://www.domain.com/index.htm”, MessageBodyType.Html, Encoding.Default, 
ImportBodyOptions.ImportRelatedFiles | ImportBodyOptions.ImportRelatedFilesFromUris)
 
            Try
                oMailer.Send()
                Console.WriteLine(“The message has been successfully sent.”)
            Catch e As MailBeeSmtpMessageSizeOutOfRangeException
                Console.WriteLine(“The message is too large (more than ” + e.MaxAllowedMessageSize + ” bytes).”)
            End Try
        End Sub
    End Class
End Namespace

 以上就是本次教程的全部内容,接下来会有更多相关教程,敬请关注!您也可以在评论者留下你的经验和建议。


试用、下载、了解更多产品信息请点击“咨询在线客服”   

 

标签:.NET电子邮件

来源:慧都

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

上一篇 2017年4月12日
下一篇 2017年4月12日

相关推荐

发表回复

登录后才能评论