[TUT] Sending Emails [VB] - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19) +---- Thread: [TUT] Sending Emails [VB] (/showthread.php?tid=6267) |
[TUT] Sending Emails [VB] - RaZoR03 - 04-15-2010 This tutorial is going to show you how to make a program which can send emails. I've created this for a console application, but that's not necessary. First we need to import this: Code: Imports System.Net.Mail Now we start by making a Sub, all code will be located in the same sub. Code: Private Sub SendEmail(ByVal MailFrom As String, ByVal MailPass As String, _ Here we got: MailFrom Your mail address MailPass Your password MailTo the person who you want to send the mail to's email address MailSubj The subject of the email MailText the text in the email MailFromName the name which is showed as the sender MailToName the name which is showed as the target MailAttach files to attach with the email, sepperated with commas Now we need to test all the variables, first: Code: If MailSubj = "" Then If there was an empty string as Subject we replaced it with "No Subject". Then we need to test the email addresses: Code: If MailTo = "" Then First we tested if the Target's Email wasn't an empty string, the we tested the Sender's email and searched for the right MailServer (I only know gmails and hotmails. You can send to everyone though). Then we check if the password exists: Code: If MailPass = "" Then Now we're creating two variables as mail addresses, we got Try,catch blocks if the email addresses shouldn't be valid: Code: Dim mTo As System.Net.Mail.MailAddress Now with a simple code we create the message and adds the subject and the text: Code: Dim NEWMail As New MailMessage(mFrom, mTo) Now we are going to add attachments, if their are any: Code: If MailAttach <> "" Then We just split the string to different attachment and then tried to add them as an attachment to the email. We need to create a SmtpClient, It's it which sends the mail: Code: Dim client As New SmtpClient(MailServer, 587) Now we only need to add the actual sending: Code: Console.WriteLine("Sending email...") That's it!! I will show an example how to use this: Code: Sub Main() RE: [TUT] Sending Emails [VB] - Carb0n F1ber - 04-18-2010 Ripped from --> http://forum.codecall.net/vb-tutorials/15808-sending-emails.html RE: [TUT] Sending Emails [VB] - Julie - 04-18-2010 Thanks but ripped RE: [TUT] Sending Emails [VB] - Jordan L. - 04-18-2010 Please do not leech or Rip tutorials without giving any credit to the original author. |