Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Email with attachment in Vb.net

I know most people know how to do this but i looked for a way to do it when i first started vb so im posting it here.

How to email with an attachment:
Code
Imports System.Net.Mail
Gmail:
Code
Dim Mail As New MailMessage
      Mail.Subject = "Subject"
      Mail.To.Add("To email")
      Mail.From = New MailAddress("Your email")
      Mail.Body = ("Main text")

      Dim attachment As System.Net.Mail.Attachment
      attachment = New System.Net.Mail.Attachment("Path to file")
      Mail.Attachments.Add(attachment)

      Dim SMTP As New SmtpClient("smtp.gmail.com")
      SMTP.EnableSsl = True
      SMTP.Credentials = New System.Net.NetworkCredential("Username", "Password")
      SMTP.Port = "587"
      SMTP.Send(Mail)

Hotmail/Live:
Code
Dim Mail As New MailMessage
      Mail.Subject = "Subject"
      Mail.To.Add("To email")
      Mail.From = New MailAddress("Your email")
      Mail.Body = ("Main text")

      Dim attachment As System.Net.Mail.Attachment
      attachment = New System.Net.Mail.Attachment("Path to file")
      Mail.Attachments.Add(attachment)

      Dim SMTP As New SmtpClient("smtp.Live.com")
      SMTP.EnableSsl = True
      SMTP.Credentials = New System.Net.NetworkCredential("Username", "Password")
      SMTP.Port = "587"
      SMTP.Send(Mail)
3 TO 1 Mail.Attachments.Add(New System.Net.Mail.Attachment("Path to file"))
^^
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("Path to file")
Mail.Attachments.Add(attachment)
Never knew that :) thanks
https://msdn.microsoft.com/en-us/library/7f38zh8x.aspx

Both of you!
I remember having an issue with GMail back in the day doing something like this... This will help people I'm sure so thanks for the share ;)
Nice hope I can help :) I had the same problem
Assigning a string to an int property, and you're releasing a source? u kiddin?
Well if it works it works and it does so no im not kidding
(Jun 18, 2015 12:54 PM)Strintent Wrote:  Well if it works it works and it does so no im not kidding

It won't compile with Option Strict on. He does have a point though. The port property is expecting type integer yet you're initializing with a string.
How would i change this then?
(Jun 18, 2015 01:01 PM)Strintent Wrote:  How would i change this then?

Remove the quotation marks. It's that easy!
Oh okay makes sense thanks :)


Got to wait 24 hours to update the thread :|
This is a SMTP Email modded version. XD


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by zadyofficialJun 22, 2018 11:29 AM 0 101 Jun 22, 2018 11:29 AM
Last Post: zadyofficial
[Python] by ASlopaRMay 6, 2017 11:17 AM 4 210 May 6, 2017 11:17 AM
Last Post: hunter24957
[C#] by jujugerOct 4, 2016 03:39 AM 8 305 Oct 4, 2016 03:39 AM
Last Post: jujuger