SMTP BCC feature in VB.net - vb.net

I am looking to add BCC mail feature in the following code. How can I make changes in the following code to send an auto email to more than one email's
Dim SMTPServer As New SmtpClient()
Dim Mail As New MailMessage()
SMTPServer.Credentials = New Net.NetworkCredential(" ")
SMTPServer.Port = 587
SMTPServer.Host = " "
Mail = New MailMessage
Mail.From = New MailAddress(" ")
Mail.To.Add(dr("").ToString)
Mail.Subject = "Patient Assignment"
Mail.Body = " "
SMTPServer.Send(Mail)

Related

What is the best way to send emails via VB using O365 domain?

I'm trying to send emails automatically, the configuration below worked perfectly with Gmail, but now with office365. I can't send the emails, I need help.
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New Net.NetworkCredential("xxx#xx.com", "xxxx")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.office365.com"
SmtpServer.EnableSsl = True
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
mail = New MailMessage()
mail.From = New MailAddress("xxx#xx.com")
mail.To.Add(listaCorreo)
mail.Subject = " string "
mail.Body = "string "
mail.IsBodyHtml = True
SmtpServer.Send(mail)
Catch ex As Exception
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("Class -\> ClassProcessingError, Method -\> MyContactByMail, Error -\> " & ex.Message)
End Try

I got a error while sending mail using vb.net

the error is The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. t77sm26908892pfg.102 - gsmtp
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.Credentials = New _
Net.NetworkCredential("user#gmail.com", "user1")
mail = New MailMessage()
mail.From = New MailAddress("user#gmail.com")
mail.To.Add("user2#gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
As Codexer said in his comment, you are not enabling SSL by setting SmtpServer.EnableSsl = True
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Port = 587
SmtpServer.EnableSsl = True ' <---- this
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.Credentials = New _
Net.NetworkCredential("user#gmail.com", "user1")
mail = New MailMessage()
mail.From = New MailAddress("user#gmail.com")
mail.To.Add("user2#gmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
It always a good idea to not send your credentials as plain text over the internet...

How to send a file from a shared network via E-mail in VB.NET?

I'm creating a WinService to send E-mails and now I am trying to send a file via e-mail from a shared network.
When I do the debugging I can send and receive the attachment successfully, but when I run the WinService it says that Access to the path '\\SharedPath\shared_file.txt' is denied.
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("user", "password")
SmtpServer.Host = "smtp.example.com"
SmtpServer.Port = 587
SmtpServer.EnableSsl = True
mail.From = New MailAddress("src_address#example.com")
mail.To.Add("dst_address#example.com")
mail.Subject = "E-Mail subject"
mail.Body = "Email body text."
Dim attachment As New Attachment("\\SharedPath\shared_file.txt")
mail.Attachments.Add(attachment)
SmtpServer.Send(mail)
Any suggestion?

Error when sending an email using VB Script. Need need to know if anything is wrong with this below code?

Error message:server rejected sender address 530 5.7.1.Client is not authenticated to send Anonymous Email from
Script Used:
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Test Email"
MyEmail.From="test#mail.com"
MyEmail.To="send#mail.com"
MyEmail.TextBody="Test Email"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="test#mail.com"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="---------"
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusetsl") = True
MyEmail.Configuration.Fields.Update
MyEmail.Send
Set MyEmail=nothing
Update: Changing the Port Number to 25 solved the issue. Thanks!
Hmmm , maybe you can use this source from me
Imports System.Net.Mail
Public Class Form1
Dim smtpServer As New SmtpClient()
Dim mail As New MailMessage()
smtpServer.Credentials = New Net.NetworkCredential("email#gmail.com ", "pass")
'using gmail
smtpServer.Port = 587
smtpServer.Host = "smtp.gmail.com"
smtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("From#Gmail.Here")
mail.To.Add("To#Gmail.Here")
mail.Subject = "Your Subject"
mail.Body = "Text Message Here"
smtpServer.Send(mail)

Use Progress bar for upload attachment

I have a xml file as an attachment. I searched on the internet all of them were for uploading by ftp I couldn't figure out how to use them for sending mail so how can I use progress bar to show while it is uploading to the mail?
here is my code for sending email
Dim smtpServer As New SmtpClient
Dim mail As New MailMessage()
Dim mailAttachment As Attachment = New Attachment("XMLFile")
smtpServer.UseDefaultCredentials = False
smtpServer.Credentials = New Net.NetworkCredential("a#ymail.com", "12345")
smtpServer.Port = 465
smtpServer.EnableSsl = True
smtpServer.Host = "smtp.mail.yahoo.com"
mail = New MailMessage()
mail.From = New MailAddress("a#ymail.com")
mail.To.Add("a#ymail.com")
mail.Subject = "110BackUp"
mail.IsBodyHtml = False
mail.Body = "XML FILE"
mail.Attachments.Add(mailAttachment)
smtpServer.Send(mail)
If the problem is only have the progress bar while sending the email maybe you can find useful this SO post