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
Related
I wanna send an Email from my Webservice, written in vb.net, but I get an Timeout.
What is wrong?
Dim toaddress As MailAddress = New MailAddress("xxx")
Dim fromaddress As MailAddress = New MailAddress("yyy")
' The structure for MailMessage(from, to)
Dim message As MailMessage = New MailMessage(fromaddress, toaddress)
message.Subject = "I have sent you a message from a program!"
message.Body = "Hello World!"
Dim messanger As SmtpClient = New SmtpClient("smtpxxx", 995)
messanger.Credentials = New NetworkCredential("user", "password")
messanger.EnableSsl = True
messanger.Send(message)
You are doing many things wrong and some of the information you have given are not clear enough. host name and port names have to give properly. it chooses which mail service you are using, from your code it is not correctly provided, so i will give a snippet that uses gmail to send mail. please go through this and make changes as per your SmtpHost.
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
This link help you to find the smtp.Server and Port numbers, you can use this thread for check the limitations of smtp.servers
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?
i tried uploading text files using the following vb code,
Sub mail()
On Error Resume Next
Dim mail As New MailMessage()
Dim SmtpServer As New SmtpClient
SmtpServer.Credentials = New Net.NetworkCredential("mymail#gmail.com", "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
SmtpServer.EnableSsl = True
mail.To.Add("mymail#gmail.com")
mail.From = New MailAddress("mymail#gmail.com")
mail.Subject = "files"
mail.Body = "most secure"
'mail.Attachments.Add(New Attachment("d:\b.txt"))
mail.Attachments.Add(New Attachment("d:\c.txt"))
'mail.Attachments.Add(New Attachment("d:\a.txt"))
SmtpServer.Send(mail)
End Sub
i tried uploading all three files, file a(5kb) and b(2kb) are getting uploaded but file c(126kb) is not getting uploaded, then i tried uploading only c file but mail is sent without c file. is this error is caused due to file size?? how can i solve this issue??
Am using the below code to send a mail in vb.net, this code works fine with gmail but not works with rediffmail
Mail.Subject = "test email"
Mail.To.Add(dgr.Cells("to#xyz.com")
Mail.From = New MailAddress("from#abc.com")
Mail.Body = "Hello"
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("AttachPath")
Mail.Attachments.Add(attachment)
Dim SMTP As New SmtpClient("smtp.rediffmailpro")
SMTP.EnableSsl = false
SMTP.Credentials = New System.Net.NetworkCredential("xyz#.abc.com",
"password")
SMTP.Port = 25
SMTP.Send(Mail)
any reason? or solution, so that I can sent mail using any Email ID
Try
Dim SMTP As New SmtpClient("smtp.rediffmailpro.com")
Here's my code (yes I censored my email/password) (when you click button)
Dim Mail As New MailMessage
Mail.Subject = "test email"
Mail.To.Add("*****")
Mail.From = New MailAddress("*****") '
Mail.Body = "This is an email!"
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("*****", "*****")
SMTP.Port = 587
SMTP.Send(Mail)
MsgBox("Sent Successfully")
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at (link which doesn't help)
SOLVED!
I never would have guessed.
Google wasn't letting me use my account because it was hacked. It apparently was hacked when I was writing code...
FYI, a safer version would be
Using mail As MailMessage = New MailMessage
mail.Subject = "test email"
mail.To.Add("*****")
mail.From = New MailAddress("*****") '
mail.Body = "This is an email!"
Using smtp As New SmtpClient("smtp.gmail.com")
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("*****", "*****")
smtp.Port = 587
smtp.Send(mail)
End Using
End Using
MsgBox("Sent Successfully")
This would ensure that the mail and smtp objects get cleaned up, whether or not an exception occurs.