Link to home
Start Free TrialLog in
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

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

' 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)
Avatar of g7bmp
g7bmp

ASKER

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.
What error do you get ?
Avatar of g7bmp

ASKER

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
your server surely blocks relay. see http://www.systemnetmail.com/
Avatar of g7bmp

ASKER

Would  not this block all mail not just the ones with attchments
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 @@@@"
Avatar of g7bmp

ASKER

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

ASKER

Still in need of help please
is it possible that there are rules on the server that block some attachment? talk to your sysadmin.
Avatar of g7bmp

ASKER

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
>>it will not send to another domain

Back to sqare one. Relay is blocked. See http://www.systemnetmail.com/faq/1.4.aspx
Avatar of g7bmp

ASKER

All computers on the domain are allowed to relay mail
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of g7bmp

ASKER

Used google SMTP works fine thanks