file is not uploaded while sending mail with attachment in vb - vb.net

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??

Related

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?

getting error when i am sending mail via smtp

Dim MESSAGE As New MailMessage()
MESSAGE.From = New MailAddress(Mail_From)
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.To.Add(email)
MESSAGE.Subject = "Testing"
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.Body = msg
Dim smtp As New SmtpClient()
smtp.Host = SMTP_Host
smtp.Port = SMTP_Port
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential(Mail_User, Mail_PW)
smtp.EnableSsl = False
smtp.Send(MESSAGE)
i got error:
MAIL Error Message:Mailbox unavailable. The server response was:
This email has identified as high probability of being a spam mail
by our
The mail has been rejected by the server, there is nothing you can do to resolve this. You could in theory attempt to modify the content so that is does not appear as spammy, but this is likely to be a long and tedious process.

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

Sending Mail in Vb.net using vb.net

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")

SMTP.Send(Mail) Error

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.