Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ivan  
#1 Posted : Tuesday, March 29, 2011 5:58:52 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
In this topic, I will introduce how to send email in VB using SMTP/EWS/WebDAV. I will also introduce some advanced features including SSL, S/MIME, Embedded Images, Email Queue and Multiple Threads.

Click here to read original tutorial ...


Tutorial Index

•Send Email using SMTP protocol in A Simple C# Project
•Send Email over SSL connection
•Send Email using Gmail
•Send Email using Yahoo
•Send Email using Hotmail/Live/Office 365 in C#
•Send Email directly without SMTP server(MX DNS lookup) in C#
•Send HTML Email in C#
•Send Email with Attachment in C#
•Send Email with Embedded Images in C#
•Send Email with Digital Signature in C# - S/MIME
•Encrypt Email in C# - S/MIME
•Send Email with Event Handler in C#
•Send Email Asynchronously in C#
•Send Email with Multiple Threads(Mass Mail) in C#
•Send Email with Queue in ASP.NET, C#
•Send Mass Emails using Database Queue in ASP.NET, C#
•Send Email using Exchange Web Service - EWS in C#
•Send Email using Exchange WebDAV in C#


Installation
Before you can use the following sample codes, you should download the EASendMail Installer and install it on your machine at first.

A simple VB.NET project

To better demonstrate how to send email using SMTP protocol, let's create a VB console project at first, and then add the reference of EASendMail in your project.

vb send email sample project

Add Reference of EASendMail to Visual Stuido VB.NET Project

To use EASendMail SMTP Component in your project, the first step is "Add reference of EASendMail to your project". Please create/open your project with Visual Studio.NET, then choose menu->"Project"->"Add Reference"->".NET"->"Browse...", and choose the EASendMail{version}.dll from your disk, click "Open"->"OK", the reference of EASendMail will be added to your project, and you can start to use it to send email in your project.

Add SMTP Component Reference

Because EASendMail has separate builds for .Net Framework, please refer to the following table and choose the correct dll.

Separate builds of run-time assembly for .Net Framework 1.1, 2.0, 3.5, 4.0 and .Net Compact Framework 2.0, 3.5.


EASendMail.dll

Built with .NET Framework 1.1
It requires .NET Framework 1.1, 2.0, 3.5 or later version.

EASendMail20.dll

Built with .NET Framework 2.0
It requires .NET Framework 2.0, 3.5 or later version.

EASendMail35.dll

Built with .NET Framework 3.5
It requires .NET Framework 3.5 or later version.

EASendMaill40.dll

Built with .NET Framework 4.0
It requires .NET Framework 4.0 or later version.

EASendMaill45.dll

Built with .NET Framework 4.5
It requires .NET Framework 4.5 or later version.

EASendMailCF20.dll

Built with .NET Compact Framework 2.0
It requires .NET Compact Framework 2.0, 3.5 or later version.

EASendMailCF35.dll

Built with .NET Compact Framework 3.5
It requires .NET Compact Framework 3.5 or later version.

Now add the following codes to the project and change From, To, Server, User and Password to corresponding value.

[VB - Send Email Example]

Imports EASendMail ' Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module


If you set everything right, you can get "email was sent successfully". If you get "failed to send email with the following error:", then please have a look at the following section.

Edited by user Sunday, July 28, 2013 5:17:19 AM(UTC)  | Reason: Not specified

ivan  
#2 Posted : Tuesday, July 9, 2013 12:16:41 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Where can I get my SMTP email server address, user and password?

Because each email account provider has different server address, so you should query your SMTP server address from your email account provider. To prevent spreading email from the server, most SMTP servers also require user authentication. User name is your email address or your email address without domain part, it depends on your email provider setting.

When you execute above example code, if you get error about "Networking connection" or "No such host", it is likely that your SMTP server address is not correct. If you get an error like "5xx Relay denied", it is likely that you did not set user authentication. Another common error is "5xx Must issue a STARTTLS command first" or "No supported authentication marshal found!", that is because your SMTP server requires user authentication under SSL/TLS connection. You can set the SSL/TLS connection to solve this problem.

Finally, if you have already set your account in your email client such as Outlook or Window Mail, you can query your SMTP server address, user in your email client. For example, you can choose menu -> "Tools" - > - "Accounts" - > "Your email account" - > "Properties" - > "Servers" in Outlook express or Windows Mail to get your SMTP server, user. Using EASendMail to send email does not require you have email client installed on your machine or MAPI, however you can query your exist email accounts in your email client.

vb email setting

Email Address Syntax and Multiple Recipients

Mail Address Syntax in EASendMail SMTP Component:

For single email address (From, ReplyTo, ReturnPath), the syntax can be: ["][display name]["]<email address>.
For example: "Tester, T" <test@adminsystem.com>, Tester <test@adminsystem.com>, <test@adminsystem.com> or test@adminsystem.com.

For mulitple email address (To, CC, Bcc), the syntax can be: [single email],[single email]... (,;\r\n) can be used to separate multiple email addresses.
For example: "Tester, T" <test1@adminsystem.com>, Tester2 <test2@adminsystem.com>, <test3@adminsystem.com>, test4@adminsystem.com

[VB - Email Syntax - Example]
To better understand the email address syntax, please refer to the following codes.


' From is a MailAddress object, it supports implicit converting from string.
' The syntax is like this: "test@adminsystem.com" or "Tester<test@adminsystem.com>"
' The example code without implicit converting.
oMail.From = New MailAddress("Tester", "test@adminsystem.com")
oMail.From = New MailAddress("Tester<test@adminsystem.com>")
oMail.From = New MailAddress("test@adminsystem.com")

' To, Cc and Bcc is a AddressCollection object, it supports implicit converting
' from string. Multiple addresses are separated with (,;)
' The syntax is like this: "test@adminsystem.com, test1@adminsystem.com"

' The example code without implicit converting
oMail.To = New AddressCollection("test1@adminsystem.com, test2@adminsystem.com")
oMail.To = New AddressCollection("Test1<test@adminsystem.com>, Test2<test2@adminsystem.com>")

' You can add more recipient by Add method
oMail.To.Add(New MailAddress("tester", "test@adminsystem.com")

' You can also add carbon copy (CC) or blind carbon copy (BCC) in the email.
oMail.Cc.Add(New MailAddress("CC recipient", "cc@adminsystem.com"))
oMail.Bcc.Add(New MailAddress("Bcc recipient", "bcc@adminsystem.com"))


Reply-To, Return-Path and Mail Priority

If you want to set another email address to get the replied email rather than your From address, you can use ReplyTo property.
If you want to set another email address to get the delivery report rather than your From address, you can use ReturnPath property.
If you want to set Higher or Lower priority to your email, you can use Priority prority.

[VB - Email ReplyTo, ReturnPath and Priority]

oMail.From = "Tester <test@emailarchitect.net>"

' Set the Reply-To address
oMail.ReplyTo = "replyto@@emailarchitect.net"

' Set the email address to receive delivery report
oMail.ReturnPath = "report@emailarchitect.net"

' Set high priority
oMail.Priority = MailPriority.High

Edited by user Tuesday, July 9, 2013 12:53:15 AM(UTC)  | Reason: Not specified

ivan  
#3 Posted : Tuesday, July 9, 2013 12:21:11 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email over SSL/TLS in VB

SSL/TLS connection encrypts data between the SMTP component and SMTP server to protects user, password and email content in TCP/IP level. Now this technology is commonly used and many SMTP servers are deployed with SSL such as gmail, yahoo and hotmail.

There are two ways to deploy SSL on SMTP server:
1. Using STARTTLS command to switch SSL channel on normal SMTP port (25 or 587);
2. Deploying SSL on another port (465 or other port, you may query it from your server administrator) directly.

EASendMail SMTP component supports both ways. The connection can be specified by EASendMail.SmtpConnectType enumeration. Please see the following example code.

[VB - Set SSL/TLS Connection]

' Send email by normal TCP/IP without SSL connection
Dim oServer As New SmtpServer("localhost 25")
oServer.ConnectType = SmtpConnectType.ConnectNormal

' Send email by SSL connection with STARTTLS command switching
Dim oServer As New SmtpServer("localhost 25")
oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS

' Send email by SSL connection with direct SSL.
Dim oServer As New SmtpServer("localhost 465")
oServer.ConnectType = SmtpConnectType.ConnectDirectSSL

' Send email by SSL connection with auto-detect.
' If port is 25 or 587, STARTTLS SSL will be used; otherwise direct SSL will be used.

Dim oServer As New SmtpServer("localhost 465")
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Dim oServer As New SmtpServer("localhost 25")
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto



[VB - Send email over direct SSL on 465 port]
The following example codes demonstrate how to use send email over direct SSL connection on 465 port.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' Set SSL 465 port
oServer.Port = 465

' Set direct SSL connection
oServer.ConnectType = SmtpConnectType.ConnectDirectSSL

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module


[VB- Send email over TLS on 25 or 587 port]
The following example codes demonstrate how to send email with TLS (STARTTLS command) connection on 25 port.


Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

// Set 25 port
oServer.Port = 25;

// Set TLS connection
oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

Edited by user Tuesday, July 9, 2013 12:52:00 AM(UTC)  | Reason: Not specified

ivan  
#4 Posted : Tuesday, July 9, 2013 12:25:47 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Now most email providers such as Gmail, Yahoo, Hotmail requires the SSL or TLS connection. To better demonstrates how to send email over SSL/TLS, here are several examples.

Send Email using Gmail

Gmail SMTP server address is "smtp.gmail.com". It requires SSL or TLS connection, and you should use your Gmail email address as the user name for ESMTP authentication. For example: your email is "gmailid@gmail.com", and then the user name should be "gmailid@gmail.com".

[VB - Send email using Gmail]
The following example codes demonstrate how to send email using Gmail account.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Your gmail email address
oMail.From = "gmailid@gmail.com"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from gmail account"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project with gmail"

'Gmail SMTP server address
Dim oServer As New SmtpServer("smtp.gmail.com")

' If you want to use direct SSL 465 port,
' please add this line, otherwise TLS will be used.
' oServer.Port = 465

' detect SSL/TLS automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

' Gmail user authentication should use your
' Gmail email address as the user name.
' For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com"
oServer.User = "gmailid"
oServer.Password = "yourpassword"

Try

Console.WriteLine("start to send email over SSL ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

Edited by user Tuesday, July 9, 2013 12:51:22 AM(UTC)  | Reason: Not specified

ivan  
#5 Posted : Tuesday, July 9, 2013 12:27:27 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email using Yahoo

Yahoo SMTP server address is "smtp.mail.yahoo.com". It supports direct SSL connection to do user authentication, and you should use your Yahoo email address as the user name for ESMTP authentication. For example: your email is "myid@yahoo.com", and then the user name should be "myid@yahoo.com".

[VB - Send email using Yahoo account over direct SSL connection]
The following example codes demonstrate how to use send email using Yahoo account.


Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Your Yahoo email address
oMail.From = "myid@yahoo.com"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from yahoo account"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project with yahoo"

' Yahoo SMTP server address
Dim oServer As New SmtpServer("smtp.mail.yahoo.com")

' For example: your email is "myid@yahoo.com", then the user should be "myid@yahoo.com"
oServer.User = "myid@yahoo.com"
oServer.Password = "yourpassword"

' Because yahoo deploys SMTP server on 465 port with direct SSL connection.
' So we should change the port to 465.
oServer.Port = 465

' detect SSL/TLS type automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email over SSL ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

Edited by user Tuesday, July 9, 2013 12:50:45 AM(UTC)  | Reason: Not specified

ivan  
#6 Posted : Tuesday, July 9, 2013 12:28:55 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email using Hotmail/MSN Live

Hotmail/MSN Live SMTP server address is "smtp.live.com". It requires TLS connection to do user authentication, and you should use your Hotmail/MSN Live email address as the user name for ESMTP authentication. For example: your email is "liveid@hotmail.com", and then the user name should be "myid@hotmail.com".


[VB - Send email using Hotmail/MSN Live account over TLS connection]
The following example codes demonstrate how to use to send email using Hotmail/MSN Live account.


Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Your hotmail email address
oMail.From = "liveid@hotmail.com"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from hotmail account"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project with hotmail"

' Hotmail SMTP server address
Dim oServer As New SmtpServer("smtp.live.com")

' Hotmail user authentication should use your
' email address as the user name.
oServer.User = "liveid@hotmail.com"
oServer.Password = "yourpassword"

' detect SSL/TLS connection automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email over TLS ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

Edited by user Tuesday, July 9, 2013 12:50:20 AM(UTC)  | Reason: Not specified

ivan  
#7 Posted : Wednesday, July 10, 2013 4:32:31 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send email without specified SMTP server (MX record DNS lookup)

In general, we send email via specified SMTP server. How does the specified SMTP server know what address this email should be sent to? The answer is... it queries MX record of recipient's domain via DNS lookup. It then forwards this email to the SMTP server queried from DNS server. If recipient's server doesn't work fine, sender's SMTP server will send a failure-delivery report to the sender telling it failed to send out the email.

How does EASendMail SMTP component work with "Send email directly"? Firstly, it queries MX record for recipient address from DNS, then sends email to recipient's email server directly. In short, if no SMTP server is specified in the code, EASendMail will send email to recipient directly. Since querying DNS server consumes CPU time and networking resource, the performance of "Send email directly" is lower than sending email with specified SMTP server. Moreover, nowadays more and more SMTP servers block email sent from dynamic IP address, so we don't recommend you to use "Direct Send Email" except you have a static IP address or you encounter problem with your ISP SMTP server.

Every recipient may have different SMTP server, if there are multiple recipients in one message and you want to send email directly, you should send the email to the recipients one by one.

To implement this feature, you just need to put nothing to SMTP server address.

[VB - Send email without specified SMTP server (MX record DNS lookup)]
The following example codes demonstrate how to send email using DNS lookup.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "direct email sent from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project directly"

' Set SMTP server address to ""
Dim oServer As New SmtpServer("")

' Do not set user authentication
' Do not set SSL connection

Try

Console.WriteLine("start to send email directly ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module


With above code, if you get error like "5xx IP address rejected", that means your IP address is blocked by the recipient's SMTP server. You have to specify a SMTP server with user authentication to relay your email.

In our solid experience, we don't suggest that you send email directly.

If your IP address is dynamic, most SMTP servers reject your connection due to anti-spam policy. We always suggest that your send email by a SMTP server that has a static internet IP address. When you relay email by your SMTP server, because you do user authentication at first before you send email to your SMTP server, so your SMTP server doesn’t reject your connection even your IP address is dynamic. Finally your SMTP server sends email to remote SMTP server. Because your SMTP server has a static IP, the email won’t be rejected by remote SMTP server.

send email using DNS lookkup

If you encountered a temporal SMTP error (4xx), you should retry to send email later. That means you have to write the code to handle retry. So if you have a static IP address, I suggest that you use EASendMail Component + EASendMail Service, EASendMail service can send email directly or send email with specified SMTP server in background and handle delivery retry automatically.

To learn more detail about EASendMail Serivce, please have a look at Work with EASendMail Service (Email Queuing).

Edited by user Wednesday, July 10, 2013 4:34:44 AM(UTC)  | Reason: Not specified

ivan  
#8 Posted : Wednesday, July 10, 2013 4:38:03 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send HTML Email

If you want to specify the font, color or insert pictures in your email, you should use Html email format instead of Plain text email format.

[VB - Send HTML email]
The following example codes demonstrate how to send email in HTML body format.
Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test HTML email from VB.NET project"

' Set HTML body
oMail.HtmlBody = "<font size=5>This is</font> <font color=red><b>a test</b></font>"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your SMTP server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send HTML email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module


After you received the email by your email client, the body text is like this:

UserPostedImage


Of course, you don't have to write the HTML source body text in your application manually. You can build a html file with HTML tools and use ImportHtmlBody method to import the html file directly.

You can also refer to the htmlmail.* samples in EASendMail Installer. Those samples demonstrate how to build a HTML email editor and send HTML email with attachment or embedded images/pictures.

UserPostedImage

Edited by user Wednesday, July 10, 2013 4:39:41 AM(UTC)  | Reason: Not specified

ivan  
#9 Posted : Sunday, July 14, 2013 5:02:49 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Attachment in VB

To send an email with file attachment, we need to use AddAttachment method. This method can attach a file to the email message from local disk or a remote URL.


[VB - Add attachment from local disk or remote URL]
The following example codes demonstrate how to send email with file attachments.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test HTML email with attachment"

' Set HTML body
oMail.HtmlBody = "<font size=5>This is</font> <font color=red><b>a test</b></font>"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

' Add attachment from local disk
oMail.AddAttachment( "d:\test.pdf" )

' Add attachment from remote website
oMail.AddAttachment( "http://www.emailarchitect.net/webapp/img/logo.jpg" )

Console.WriteLine("start to send email with attachment ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#10 Posted : Tuesday, July 16, 2013 6:07:02 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Embedded Images in VB

To attach an embedded images to email, you should add an attachment to email at first. Then you should assign an unique identifier(contentid) to this attachment. Finally, you need to replace the <img src="your file name" /> to <img src="cid:yourcontentid" />.



[VB - Add embedded images to email]
The following example codes demonstrate how to send email with embedded images.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test HTML email with embedded image"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

' Add image attachment from local disk
Dim oAttachment As Attachment = oMail.AddAttachment("d:\test.gif")

' Specifies the attachment as an embedded picture
' contentid can be any string.
Dim contentID As String = "test001@host"
oAttachment.ContentID = contentID
oMail.HtmlBody = "<html><body>this is a <img src=""cid:" _
+ contentID + """> embedded picture.</body></html>"

Console.WriteLine("start to send email with embedded image ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module


To attach embedded images/pictures, SmtpMail.ImportHtmlBody and SmtpMail.ImportHtml methods are strongly recommended. With these methods, you don't have to specify the ContentID manually. The html source/file html body can be imported to email with embedded pictures automatically.

You can also refer to the htmlmail.* samples in EASendMail Installer. Those samples demonstrate how to build a HTML email editor and send HTML email with attachment or embedded images/pictures.

UserPostedImage
ivan  
#11 Posted : Tuesday, July 16, 2013 6:32:04 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Digital Signature in VB - S/MIME

Digital signature prevents email content is faked or changed in transport level. Encrypting email protects email content from exposure to inappropriate recipients. Both digital signature and email encrypting depend on digital certificate.

If you have an email digital signature certificate installed on your machine, you can find it in "Control Panel" -> "Internet Options" -> "Content" -> "Certificates" -> "Personal".

UserPostedImage

Then you can use your email certificate to sign the email by the following code. If you don't have a certificate for your email address, you MUST get a digital certificate for personal email protection from third-party certificate authorities such as www.verisign.com.

If you need a free certificate for your email address, you can go to http://www.comodo.com/ho...ee-email-certificate.php to apply for one year free email certificate.


[VB - Send email with digital signature (S/MIME)]
The following example codes demonstrate how to sign email with digital certificate.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email with digital signature"

' Set email body
oMail.TextBody = "this is a test email with digital signature (S/MIME)"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

' Find certificate by email adddress in My Personal Store.
' Once the certificate is loaded to From, the email content
' will be signed automatically
oMail.From.Certificate.FindSubject(oMail.From.Address, _
Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
"My")

Catch exp As Exception

Console.WriteLine("No sign certificate found for <" + _
oMail.From.Address + ">:" + exp.Message)
End Try

Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#12 Posted : Tuesday, July 16, 2013 6:44:41 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Encrypt Email in VB.NET - S/MIME

After the recipient received your email with digital signature, the recipient can get your digital certificate public key from your digital signature. Then the recipient can encrypt an email with your public key and send it to you. Only you can decrypt this email with your private key. That is how S/MIME can protect your email content. If you don't expose your digital certificate private key to others, none can read your email which is encrypted by your public key.

If you received an email with digital signature, your email client usually stores the public key of the sender in "Control Panel" -> "Internet Options" -> "Content" -> "Certificates" -> "Other People".

Then you can use the following code to encrypt email and send it to your recipient.

[VB - Encrypt Email (S/MIME)]
The following example codes demonstrate how to encrypt email with digital certificate.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test encrypted email"

' Set email body
oMail.TextBody = "this is a test email with email encryption (S/MIME)"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your SMTP server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

' Find certificate by email adddress in My Personal Store.
' Once the certificate is loaded to From, the email content
' will be signed automatically
oMail.From.Certificate.FindSubject(oMail.From.Address, _
Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
"My")

Catch exp As Exception

Console.WriteLine("No sign certificate found for <" + _
oMail.From.Address + ">:" + exp.Message)
End Try

Dim count As Integer = oMail.To.Count
For i As Integer = 0 To count - 1

Dim oAddress As MailAddress = oMail.To(i)
Try

' Find certificate by email adddress in My Other Peoples Store.
' The certificate can be also imported by *.cer file like this:
' oAddress.Certificate.Load("c:\encrypt1.cer")
' Once the certificate is loaded to MailAddress, the email content
' will be encrypted automatically

oAddress.Certificate.FindSubject(oAddress.Address, _
Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
"AddressBook")

Catch ep As Exception

Try
oAddress.Certificate.FindSubject(oAddress.Address, _
Certificate.CertificateStoreLocation.CERT_SYSTEM_STORE_CURRENT_USER, _
"My")

Catch exp As Exception

Console.WriteLine("No encryption certificate found for <" + _
oAddress.Address + ">:" + exp.Message)
End Try
End Try
Next

Try

Console.WriteLine("start to send encrypted email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

If you received digital signed and encrypted email by Windows Mail(Outlook Express), it looks like this:

UserPostedImage
ivan  
#13 Posted : Tuesday, July 16, 2013 7:05:10 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Event Handler in VB


In previous examples, after SendMail method is invoked, if you want to know the progress of the email sending, you should use Event Handler. The following sample codes demonstrate how to use Event Handler to monitor the progress of email sending.

[VB - Send email with event handler]
The following example codes demonstrate how to send email with event handler.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub OnIdle(ByVal sender As Object, ByRef cancel As Boolean)
' this event is fired when the SmtpClient is wait for response from
' smtp server, if you add Application.DoEvents in windows form application,
' it can prevent your form has no response before SendMail is not returned.
' Application.DoEvents()
End Sub

Sub OnConnected(ByVal sender As Object, ByRef cancel As Boolean)
Console.WriteLine("Connected")
End Sub


Sub OnSendingDataStream(ByVal sender As Object, ByVal sent As Integer, _
ByVal total As Integer, ByRef cancel As Boolean)
Console.WriteLine(String.Format("{0}/{1} sent", sent, total))
End Sub

Sub OnAuthorized(ByVal sender As Object, ByRef cancel As Boolean)
Console.WriteLine("Authorized")
End Sub

Sub OnSecuring(ByVal sender As Object, ByRef cancel As Boolean)
Console.WriteLine("Securing ...")
End Sub

Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET with event handler"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET with event handler"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

' Catching the following events is not necessary,
' just make the application more user friendly.
' If you use the object in asp.net/windows service or non-gui application,
' You need not to catch the following events.
' To learn more detail, please refer to the code in EASendMail EventHandler
AddHandler oSmtp.OnIdle, AddressOf OnIdle
AddHandler oSmtp.OnAuthorized, AddressOf OnAuthorized
AddHandler oSmtp.OnConnected, AddressOf OnConnected
AddHandler oSmtp.OnSecuring, AddressOf OnSecuring
AddHandler oSmtp.OnSendingDataStream, AddressOf OnSendingDataStream

Try

Console.WriteLine("start to send email with event handler ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#14 Posted : Tuesday, July 16, 2013 7:07:00 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Asynchronous Mode in VB

In synchronous mode, once SendMail method is called, it returns to application after the method is complete. Therefore, if the runtime (it depends on the networking connection and the email size) is long, your application cannot do anything before this method ends, which results "my application is blocked or halted". In contrast, in asynchronous mode, as BeginSendMail method works in background, this methods return to application immediately no matter the running method is complete or not.

[VB - Send email in asynchronous mode]
The following example codes demonstrate how to send email in asynchronous mode.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test asynchronous email from VB.NET"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET with asynchronous mode"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email in asynchronous mode ...")
Dim oResult As SmtpClientAsyncResult = oSmtp.BeginSendMail( _
oServer, oMail, Nothing, Nothing)

' Wait for the email sending...
Do While (Not oResult.IsCompleted)

Console.WriteLine("waiting..., you can do other thing!")
oResult.AsyncWaitHandle.WaitOne(50, False)
Loop

oSmtp.EndSendMail(oResult)

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#15 Posted : Tuesday, July 16, 2013 7:08:45 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Multiple Threads(Bulk Mail) in VB

Based on asynchronous mode, you can create multiple SmtpClient instances in your application and send email in multiple threads. Here is a simple sample demonstrates how to use asynchronous mode to send email in multiple threads.

[VB - Send bulk email with multiple threads]
The following example codes demonstrate how to send bulk email with multiple threads.

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim arRcpt() As String = {"test1@adminsystem.com", _
"test2@adminsystem.com", _
"test3@adminsystem.com"}

Dim nRcpt As Integer = arRcpt.Length
Dim arMail(nRcpt - 1) As SmtpMail
Dim arSmtp(nRcpt - 1) As SmtpClient
Dim arResult(nRcpt - 1) As SmtpClientAsyncResult

For i As Integer = 0 To nRcpt - 1
arMail(i) = New SmtpMail("TryIt")
arSmtp(i) = New SmtpClient()
Next

For i As Integer = 0 To nRcpt - 1

Dim oMail As SmtpMail = arMail(i)
' Set sender email address
oMail.From = "sender@emailarchitect.net"

' Set recipient email address
oMail.To = arRcpt(i)

' Set email subject
oMail.Subject = "mass email test from vb.net"

' Set email body
oMail.TextBody = "test from c#, this email is sent to " + arRcpt(i)

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL/TLS connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Dim oSmtp As SmtpClient = arSmtp(i)

' Submit email to BeginSendMail method and return
' to process another email
arResult(i) = oSmtp.BeginSendMail(oServer, oMail, Nothing, Nothing)
Console.WriteLine(String.Format("Start to send email to {0} ...", _
arRcpt(i)))
Next

' all emails were sent by BeginSendMail Method
' now get result by EndSendMail method
Dim nSent As Integer = 0
Do While (nSent < nRcpt)

For i As Integer = 0 To nRcpt - 1
' this email is finished
If (arResult(i) Is Nothing) Then
Continue For
End If

' wait for specified email ...
If (Not arResult(i).AsyncWaitHandle.WaitOne(10, False)) Then
Continue For
End If

Try
' this email is finished, using EndSendMail to get result
arSmtp(i).EndSendMail(arResult(i))
Console.WriteLine(String.Format("Send email to {0} successfully", _
arRcpt(i)))

Catch ep As Exception

Console.WriteLine( _
String.Format("Failed to send email to {0} with error {1}: ", _
arRcpt(i), ep.Message))
End Try

' Set this email result to null, then it won't be processed again
arResult(i) = Nothing
nSent += 1
Next
Loop

End Sub
End Module
ivan  
#16 Posted : Wednesday, July 17, 2013 5:23:28 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email with Email Queue in ASP.NET, VB

EASendMail Service is a light and fast email delivery service which works with EASendMail SMTP Component to enable your application to send mass emails in background queue service. Along with its ability to picking recipients from database in background and sending email in specified datetime, it eases your task in developing featured email application such as newsletter application. We strongly recommend you to use EASendMail Service with your ASP.NET/Web Application.

To work with EASendMail Service, please download EASendMail Service and install it on your server. If you are using web hosting service and you don't have permission to install service on that server, EASendMail service is not suitable for you.

With EASendMail email queue feature, you do not have to code for multiple threadings. EASendMail Service can send email in background with multiple threadings automatically. You just need to adjust the maximum worker threads in EASendMail Service Manager to increase the performance. Please click here to learn more detail about EASendMail Service.

If your networking connection to your SMTP server is not very fast, EASendMail Service is absolutely solution for you. You just need to submit the email to EASendMail service queue, it is very fast because EASendMail service uses shared memory to accept email from EASendMail component, and then the service will send email in background service. It is very important to improve the response time for ASP.NET web application.


[VB - Send email with EASendMail Service Queue]
The following example codes demonstrate how to use EASendMail SMTP component to send email with EASendMail Service Queue. To get the full samples of EASendMail, please refer to Samples section.

' The following example codes demonstrate sending email message using email queue
' To get full sample projects, please download and install EASendMail on your machine.
' To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

' Add EASendMail namespace
Imports EASendMail

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email ...")
' You just need to change SendMail method to SendMailToQueue method in
' your ASP.NET web application, then EASendMail uses queue to send email.
' SendMailToQueue can be used in windows application as well.
oSmtp.SendMailToQueue(oServer, oMail)
Console.WriteLine("email was sent queue successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#17 Posted : Wednesday, July 17, 2013 5:26:26 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Bulk Emails with Database Queue in ASP.NET, VB

Although EASendMail service provides a faster way to send email in background, but there are thousands of emails in a task, the SendMailToQueue will be invoked for thousands times, obviously it is not effect way.

Therefore, EASendMail service provides a more effective way to send mass emails. In short, you just need to submit your database connection and record set once, EASendMail service will pick up the record set in background and send email to each record one by one. It is very useful to send mass emails in ASP.NET web application.

To better understand the database queue, we need to create three tables in your SQL database like this:

CREATE TABLE [dbo].[rcpts](
[uid] [bigint] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) NULL,
[email] [nvarchar](128) NOT NULL,
CONSTRAINT [PK_rcpts] PRIMARY KEY CLUSTERED
(
[uid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[errorlog](
[uid] [bigint] IDENTITY(1,1) NOT NULL,
[email] [nvarchar](128) NULL,
[server] [nvarchar](50) NULL,
[errorcode] [nvarchar](50) NULL,
[errordescription] [nvarchar](255) NULL,
CONSTRAINT [PK_errorlog] PRIMARY KEY CLUSTERED
(
[uid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[sentlog](
[uid] [bigint] IDENTITY(1,1) NOT NULL,
[server] [nvarchar](50) NULL,
[email] [nvarchar](128) NULL,
CONSTRAINT [PK_sentlog] PRIMARY KEY CLUSTERED
(
[uid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Then insert two records in table 'rcpts' like this:

UserPostedImage


[VB - Send bulk emails with EASendMail Service Database Queue]
' The following example codes demonstrate sending email message using email queue + database
' To get full sample projects, please download and install EASendMail on your machine.
' To run it correctly, please change SMTP server, user, password, sender, recipient value to yours

' Add EASendMail namespace
Imports EASendMail

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Your SMTP server address
Dim oServer As New SmtpServer("smtp.emailarchitect.net")

' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oServer.User = "test@emailarchitect.net"
oServer.Password = "testpassword"

' If your smtp server requires SSL connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

' If you want EASendMail service to send the email after 10 minutes,
' use the following code.
' oMail.Date = System.DateTime.Now.AddMinutes( 10 );

' EASendMail will use the following connection to connect to the database,
' the syntax is same as ADO connection object.
oMail.Headers.ReplaceHeader("X-Data-Connection", _
"Driver={SQL Native Client};" & _
"Server=serveraddress;Database=database;Uid=user;Pwd=password;")

' EASendMail will select the fields by the following sql statement
' before sending email,
' then pick the recipient address from specified field.
oMail.Headers.ReplaceHeader("X-Sql-Select", "SELECT uid, name, email FROM Recipients")

' pick "name" field as the recipient name and "email" field as
' the recipient address.
' you can also use {$var_srecord:fieldname} to pick any field
' in X-Sql-Select statement and put it to subject, bodytext, then EASendMail will
' replace it automatially.

oMail.Headers.ReplaceHeader("To", """{$var_srecord:name}"" <{$var_srecord:email}>")
oMail.Headers.ReplaceHeader("X-Rcpt-To", "{$var_srecord:email}")

' EASendMail service will execute the following sql statement on
' every email was sent successfully.
oMail.Headers.ReplaceHeader("X-Sql-OnSentSuccess", _
"INSERT INTO sentlog ( server, email ) VALUES( '{$var_server}', '{$var_rcptaddr}' )")

' EASendMail service will execute the following sql statement on
' every email could not be sent.
oMail.Headers.ReplaceHeader("X-Sql-OnSentError", _
"INSERT INTO errorlog( email, server, errorcode, errordescription )" & _
" VALUES( '{$var_rcptaddr}', '{$var_server}', '{$var_errcode}', '{$var_errdesc}' )")

Dim s As String = "Hi {$var_srecord:name}, " & vbCrLf
s += "this sample demonstrates how to send email using email queue." & vbCrLf & vbCrLf
s += "Your id in database is {$var_srecord:uid}." & vbCrLf & vbCrLf
s += "No matter how many recipients there are, EASendMail "
s += "service will send the email in background." & vbCrLf
oMail.TextBody = s

' {$var_srecord:uid} {$var_srecord:name} {$var_srecord:email} in
' body text will
' be replaced by EASendMail automatically.

Try

Console.WriteLine("start to send email ...")

' You just need to change SendMail method to SendMailToQueue method in
' your ASP.NET web application, then EASendMail uses queue to send email.
' SendMailToQueue can be used in windows application as well.

oSmtp.SendMailToQueue(oServer, oMail)
Console.WriteLine("email was sent queue successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module

With above codes, no matter how many records in your table, SendMailToQueue is only invoked once and EASendMail service will pick up records in background and send the email based on each record to recipient one by one. It also inserts the results back to "errorlog" and "sentlog" tables automatically. You can open EASendMail Service Manager to monitor the queue and view Journal -> System Error to check if there is error with your database connection and SQL statement.
ivan  
#18 Posted : Wednesday, July 17, 2013 5:29:20 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email using Exchange Web Service - EWS in VB

Exchange Web Services (EWS), an alternative to the MAPI protocol, is a documented SOAP based protocol introduced with Exchange Server 2007. We can use HTTP or HTTPS protocol to send email with Exchange Web Services (EWS) instead of SMTP protocol.

With EASendMail SMTP Component, you do not have to build your EWS SOAP XML request and parse the response. It wraps the SOAP XML and HTTP request automatically. You just need to change the SmtpServer.Protocol property, and then EASendMail uses Web Service protocol to send email. Your server SHOULD be Exchange 2007 or later version; otherwise you cannot use Exchange Web Service protocol.

SMTP protocol
Standard SMTP protocol based on TCP/IP, all email servers support this protocol, Exchange Server also supports SMTP protocol. Using SMTP protocol is always recommended.

Exchange WebDAV
Exchange WebDAV is a set of methods based on the HTTP protocol to manage users, messages in Microsoft Exchange Server. We can use HTTP or HTTP/HTTPS protocol to send email with Exchange WebDAV instead of SMTP protocol. But since Exchange 2007, WebDAV service is disabled by default, so we only suggest that you use WebDAV protocol in Exchange 2000/2003.

Exchange Web Service (EWS)
xchange Web Services (EWS), an alternative to the MAPI protocol, is a documented SOAP based protocol introduced with Exchange Server 2007. We can use HTTP or HTTPS protocol to send email with Exchange Web Services (EWS) instead of SMTP protocol. We only suggest that you use Web Service protocol in Exchange 2007/2010/2013 or later version.

[VB - Send email using Exchange Web Service - EWS]
The following example codes demonstrate how to send email with Exchange Web Service (EWS).


Imports EASendMail ' Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your Exchange server address
Dim oServer As New SmtpServer("exch.emailarchitect.net")

' Set Exchange Web Service protocol (EWS) - Exchange 2007/2010
oServer.Protocol = ServerProtocol.ExchangeEWS

' User and password for Exchange User authentication
oServer.User = "test"
oServer.Password = "testpassword"

' By default, Exchange Web Service requires SSL connection
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#19 Posted : Wednesday, July 17, 2013 5:30:59 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Send Email using Exchange WebDAV in VB

Exchange WebDAV is a set of methods based on the HTTP protocol to manage users, messages in Microsoft Exchange Server. We can use HTTP or HTTPS protocol to send email with Exchange WebDAV instead of SMTP protocol.

With EASendMail SMTP Component, you do not have to build your WebDAV request and parse the response. It wraps the WebDAV HTTP request automatically. You just need to change the SmtpServer.Protocol property, and then EASendMail uses WebDAV protocol to send email. Your server SHOULD be Exchange 2000 or 2003 version; otherwise you cannot use Exchange WebDAV protocol. Although Exchange 2007 still supports WebDAV protocol, but the default status of WebDAV in Exchange 2007 is disabled, so you should use Exchange Web Service protocol with Exchange 2007 or later version.


[VB - Send email with Exchange WebDAV]
The following example codes demonstrate how to send email with Exchange WebDAV.

Imports EASendMail ' Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Set sender email address, please change it to yours
oMail.From = "test@emailarchitect.net"

' Set recipient email address, please change it to yours
oMail.To = "support@emailarchitect.net"

' Set email subject
oMail.Subject = "test email from VB.NET project"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project, do not reply"

' Your Exchange server address
Dim oServer As New SmtpServer("exch.emailarchitect.net")

' Set Exchange WebDAV protocol - Exchange 2000/2003
oServer.Protocol = ServerProtocol.ExchangeWebDav

' User and password for Exchange User authentication
oServer.User = "test"
oServer.Password = "testpassword"

' If Exchange WebDAV requires SSL connection, please add this line
' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto


Try

Console.WriteLine("start to send email ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception

Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try

End Sub
End Module
ivan  
#20 Posted : Wednesday, July 17, 2013 5:32:08 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
The End.

Download EASendMail from:
http://www.emailarchitect.net/downloads.aspx?cat=1

Any comments, questions are welcome.
tonydevgr  
#21 Posted : Thursday, June 16, 2022 11:15:28 PM(UTC)
tonydevgr

Rank: Newbie

Groups: Registered
Joined: 6/16/2022(UTC)
Posts: 0
Greece

Hello ivan.

I tried your example about sending email using Exchange Web Service - EWS in VB. As I read in the related tutorial Office365 supports EWS. However, when I run your code I get the following message:
"failed to send email with the following error:
Specified method is not supported."

FYI: I have an email account in Office365 cloud and enabled the following options: Oulook on the web, outlook desktop (MAPI), Exchange web services, Mobile (Exchange ActiveSync)

Can you help me with this error?

Below is the code I use:

Sub Main(args As String())
Try
Dim oMail As New SmtpMail("TryIt")
' Set sender email address, please change it to yours
oMail.From = "my_email_address_in_office365"
' Set recipient email address, please change it to yours
oMail.To = "recipient_email_address"

' Set email subject
oMail.Subject = "test email"
' Set email body
oMail.TextBody = "this is a test email sent with ews"

' Your Exchange server address
Dim oServer As New SmtpServer("outlook.office365.com/EWS/Exchange.asmx")

' Set Exchange Web Service protocol (EWS) - Exchange 2007/2010/2013/2016/2019/Office365
oServer.Protocol = ServerProtocol.ExchangeEWS

' User and password for Exchange User authentication
oServer.User = "my_email_address_in_office365"
oServer.Password = "my_password"

' By default, Exchange Web Service requires SSL connection
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Console.WriteLine("start to send email ...")

Dim oSmtp As New SmtpClient()
oSmtp.SendMail(oServer, oMail)

Console.WriteLine("email was sent successfully!")
Catch ep As Exception
Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try
End Sub
ivan  
#22 Posted : Tuesday, June 21, 2022 2:12:50 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
Originally Posted by: tonydevgr Go to Quoted Post
Hello ivan.

I tried your example about sending email using Exchange Web Service - EWS in VB. As I read in the related tutorial Office365 supports EWS. However, when I run your code I get the following message:
"failed to send email with the following error:
Specified method is not supported."

FYI: I have an email account in Office365 cloud and enabled the following options: Oulook on the web, outlook desktop (MAPI), Exchange web services, Mobile (Exchange ActiveSync)

Can you help me with this error?

Below is the code I use:

Sub Main(args As String())
Try
Dim oMail As New SmtpMail("TryIt")
' Set sender email address, please change it to yours
oMail.From = "my_email_address_in_office365"
' Set recipient email address, please change it to yours
oMail.To = "recipient_email_address"

' Set email subject
oMail.Subject = "test email"
' Set email body
oMail.TextBody = "this is a test email sent with ews"

' Your Exchange server address
Dim oServer As New SmtpServer("outlook.office365.com/EWS/Exchange.asmx")

' Set Exchange Web Service protocol (EWS) - Exchange 2007/2010/2013/2016/2019/Office365
oServer.Protocol = ServerProtocol.ExchangeEWS

' User and password for Exchange User authentication
oServer.User = "my_email_address_in_office365"
oServer.Password = "my_password"

' By default, Exchange Web Service requires SSL connection
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

Console.WriteLine("start to send email ...")

Dim oSmtp As New SmtpClient()
oSmtp.SendMail(oServer, oMail)

Console.WriteLine("email was sent successfully!")
Catch ep As Exception
Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try
End Sub



Try to change
Dim oServer As New SmtpServer("outlook.office365.com/EWS/Exchange.asmx")

to

Dim oServer As New SmtpServer("outlook.office365.com")

and see if it works, if it doesn't work, please generate a log file and send it to our support email address for assistance.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.904 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.