Avatar of g7bmp
g7bmp asked on

Help with sending mail Attachment

I am using System.Net.Mail to send e-mail from my program this works fine until i attach a file. The email then gets binned? sent to admin with a message saying that the e-mail account does not exist. This only happens when i add an attachment. Also if i try to send a message outside if the company say to a goggle mail address  an error occurs   @@@Mailbox unavailable. The server response was: 5.7.1 Unable to relay for @@@@
All address go when sent via outlook.

Any help would be appreciated
ByVal recipient As String, ByVal subject As String, _
        ByVal body As String, Optional ByVal attachmentString As String = "")
        Dim fromAddress As New MailAddress(sender)
        Dim toAddress As New MailAddress(recipient)
        Dim message As New MailMessage(fromAddress, toAddress)
 
        Dim mailSender As SmtpClient
        ' Change the Smtp server name on the next line
        mailSender = New SmtpClient("sprintmail", 25)
 
        message.Bcc.Add(fromAddress)
        message.Subject = subject
        message.IsBodyHtml = False
        message.Body = body
 
 
        If Not attachmentString = "" Then
            Dim msgAttach As New Attachment(attachmentString)
            message.Attachments.Add(msgAttach)
        End If
 
        Try
            mailSender.Send(message)
        Catch ex As Exception
            MsgBox("Error sending mail")
        End Try

Open in new window

Email Servers.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
g7bmp

8/22/2022 - Mon
Dirk Haest

' Create the file attachment for this e-mail message.
Dim data As New Attachment(file, MediaTypeNames.Application.Octet)
' Add time stamp information for the file.
Dim disposition As ContentDisposition = data.ContentDisposition
disposition.CreationDate = System.IO.File.GetCreationTime(file)
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file)
disposition.ReadDate = System.IO.File.GetLastAccessTime(file)
' Add the file attachment to this e-mail message.
message.Attachments.Add(data)
ASKER
g7bmp

I have just tried this and get  loads of errors Attaching the file is not the problem though. It does attach but does not then send the mail to the recipient. says it is not a valid address. This only happens when there is a file attached.
Dirk Haest

What error do you get ?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
g7bmp

As below
The account does exist and will go if there is no file attched
 

The following recipient(s) could not be reached:

 

     

            The e-mail account does not exist at the organization this message was sent to.  Check the e-mail address, or contact the recipient directly to find out the correct address.

            SprintMail.Sprint.local

 

      Control on 28/05/2008 17:00

            The e-mail account does not exist at the organization this message was sent to.  Check the e-mail address, or contact the recipient directly to find out the correct address.

            SprintMail.Sprint.local
Éric Moreau

your server surely blocks relay. see http://www.systemnetmail.com/
ASKER
g7bmp

Would  not this block all mail not just the ones with attchments
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Éric Moreau

I was targetting your "Also if i try to send a message outside if the company say to a goggle mail address  an error occurs   @@@Mailbox unavailable. The server response was: 5.7.1 Unable to relay for @@@@"
ASKER
g7bmp

Oh ok thank for that but still have this attachment issue
ASKER
g7bmp

Still in need of help please
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Éric Moreau

is it possible that there are rules on the server that block some attachment? talk to your sysadmin.
ASKER
g7bmp

Hi
There are no rules on the system that block attacments and i have just found out that it will not send to another domain ie google. think it is an exchange problem but do not know what. as i can send from outlook
Éric Moreau

>>it will not send to another domain

Back to sqare one. Relay is blocked. See http://www.systemnetmail.com/faq/1.4.aspx
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
g7bmp

All computers on the domain are allowed to relay mail
ASKER CERTIFIED SOLUTION
Éric Moreau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
g7bmp

Used google SMTP works fine thanks