473,748 Members | 11,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Attaching multiple files of any type to a mail message?

I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments, usually
two and they can be either text or sounds (wav files) or images (bmp, gif or
tiff)

I can send the email messages OK but the attachments are giving me grief.

Can anyone provide some code that adds attachments to web mail messages.

Thanks for any help,
Bob

Nov 28 '06 #1
5 2367
Robert,

It depends how you sent the email. If you use the default client method, you
cannot use attachment.
If you use SMTP (only on "profession al and 2003 OS") than you can use SMTP
mail.

So let us know what you are doing?

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ey******** ******@TK2MSFTN GP04.phx.gbl...
>I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments, usually
two and they can be either text or sounds (wav files) or images (bmp, gif
or tiff)

I can send the email messages OK but the attachments are giving me grief.

Can anyone provide some code that adds attachments to web mail messages.

Thanks for any help,
Bob

Nov 29 '06 #2
Cor this is the snippet of code that I use so far,
Imports System.Web.Mail

Public Class clsWebMail

Public Sub SendWebMail(ByV al Mailto As String, _

ByVal MailFrom As String, _

ByVal Subject As String, _

ByVal Body As String, _

Optional ByVal MailAttachments As String = "", _

Optional ByVal MailCC As String = "", _

Optional ByVal MailBcc As String = "", _

Optional ByVal ServerName As String = "localhost" , _

Optional ByVal UserLogin As String = "", _

Optional ByVal Password As String = "")

'The mail attachments string should contain semi colon delimited full
pathnames

'of the files to be attached.

Try

Dim mailMsg As New MailMessage

With mailMsg

..From = MailFrom

..To = Mailto

..Cc = MailCC

..Bcc = MailBcc

..Subject = Subject

..Body = Body

..Priority = MailPriority.Hi gh

End With

Dim AttachItem As String

If MailAttachments <"" Then

Dim delimStr As String = ";"

Dim delimiter As Char() = delimStr.ToChar Array()

Dim split As String() = Nothing

split = MailAttachments .Split(delimite r)

For Each AttachItem In split

Dim attachment As New MailAttachment( AttachItem) 'create the attachment for
the message

mailMsg.Attachm ents.Add(attach ment) 'add the attachment

Next AttachItem

End If

If ServerName <"localhost" Then

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1") 'basic authentication

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/sendusername",
UserLogin) 'Login name

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"Password") 'set your password here

End If

SmtpMail.SmtpSe rver = ServerName

SmtpMail.Send(m ailMsg)

Catch ex As Exception

WriteLogEntry(" Application", "WebMailing ", "Web mail send error " &
ex.InnerExcepti on.Message, EventLogEntryTy pe.Error, 0, 0)

End Try

End Sub

End Class

The code works OK except when I try to use the attachments. The project
needs to work on a Windows XP Pro or Windows 2000 workstation, it is not
intended for a 2003 server. I know that in 2005 the mailing has been moved
to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses
system.web.mail .
I found some info and code samples at
http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work and
I need it, badly.

Bob

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Robert,

It depends how you sent the email. If you use the default client method,
you cannot use attachment.
If you use SMTP (only on "profession al and 2003 OS") than you can use SMTP
mail.

So let us know what you are doing?

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ey******** ******@TK2MSFTN GP04.phx.gbl...
>>I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments, usually
two and they can be either text or sounds (wav files) or images (bmp, gif
or tiff)

I can send the email messages OK but the attachments are giving me grief.

Can anyone provide some code that adds attachments to web mail messages.

Thanks for any help,
Bob


Nov 29 '06 #3
Robert,

The first thing I thought on was "Is Robert using HTML post, because that
preservers the charachters"
Almost nobody likes that but as you have to do that, than you have no
alternatives.

At the moment I don't have the time to check your code but this is the best
website with information about your problem. If nobody else is checking your
code and you keeps the problem, than please reply I can than see if I have
the time to check it in the weekend.

http://www.systemwebmail.net/

Cor
..


"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
Cor this is the snippet of code that I use so far,
Imports System.Web.Mail

Public Class clsWebMail

Public Sub SendWebMail(ByV al Mailto As String, _

ByVal MailFrom As String, _

ByVal Subject As String, _

ByVal Body As String, _

Optional ByVal MailAttachments As String = "", _

Optional ByVal MailCC As String = "", _

Optional ByVal MailBcc As String = "", _

Optional ByVal ServerName As String = "localhost" , _

Optional ByVal UserLogin As String = "", _

Optional ByVal Password As String = "")

'The mail attachments string should contain semi colon delimited full
pathnames

'of the files to be attached.

Try

Dim mailMsg As New MailMessage

With mailMsg

.From = MailFrom

.To = Mailto

.Cc = MailCC

.Bcc = MailBcc

.Subject = Subject

.Body = Body

.Priority = MailPriority.Hi gh

End With

Dim AttachItem As String

If MailAttachments <"" Then

Dim delimStr As String = ";"

Dim delimiter As Char() = delimStr.ToChar Array()

Dim split As String() = Nothing

split = MailAttachments .Split(delimite r)

For Each AttachItem In split

Dim attachment As New MailAttachment( AttachItem) 'create the attachment
for the message

mailMsg.Attachm ents.Add(attach ment) 'add the attachment

Next AttachItem

End If

If ServerName <"localhost" Then

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1") 'basic authentication

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/sendusername",
UserLogin) 'Login name

mailMsg.Fields. Add("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"Password") 'set your password here

End If

SmtpMail.SmtpSe rver = ServerName

SmtpMail.Send(m ailMsg)

Catch ex As Exception

WriteLogEntry(" Application", "WebMailing ", "Web mail send error " &
ex.InnerExcepti on.Message, EventLogEntryTy pe.Error, 0, 0)

End Try

End Sub

End Class

The code works OK except when I try to use the attachments. The project
needs to work on a Windows XP Pro or Windows 2000 workstation, it is not
intended for a 2003 server. I know that in 2005 the mailing has been moved
to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses
system.web.mail .
I found some info and code samples at
http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work
and I need it, badly.

Bob

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Robert,

It depends how you sent the email. If you use the default client method,
you cannot use attachment.
If you use SMTP (only on "profession al and 2003 OS") than you can use
SMTP mail.

So let us know what you are doing?

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ey******* *******@TK2MSFT NGP04.phx.gbl.. .
>>>I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments,
usually two and they can be either text or sounds (wav files) or images
(bmp, gif or tiff)

I can send the email messages OK but the attachments are giving me
grief.

Can anyone provide some code that adds attachments to web mail messages.

Thanks for any help,
Bob



Nov 30 '06 #4
Cor
I looked at that site and that's where I picked up on how to do it. I did
some more testing with my code and I found that the attachments work OK when
I use localhost (i.e the built-in SMTP server that gets installed with IIS).
But I find that if I try to use an outside mail server like
mail.mycompany. com which is outside my LAN and requires a logon user name
and password, then I can't send mail messages to which I try to attach files
using my code, however if I don't try to use attachments the mail message
gets sent OK. It seems to mean that somehow one needs to do some other code
when trying to make attachments to a remote server. I could not find any
documentation or sample code on that specific problem.

Regards,
Bob
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:OV******** ******@TK2MSFTN GP02.phx.gbl...
Robert,

The first thing I thought on was "Is Robert using HTML post, because that
preservers the charachters"
Almost nobody likes that but as you have to do that, than you have no
alternatives.

At the moment I don't have the time to check your code but this is the
best website with information about your problem. If nobody else is
checking your code and you keeps the problem, than please reply I can than
see if I have the time to check it in the weekend.

http://www.systemwebmail.net/

Cor
.


"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ug******** ******@TK2MSFTN GP02.phx.gbl...
>Cor this is the snippet of code that I use so far,
Imports System.Web.Mail

Public Class clsWebMail

Public Sub SendWebMail(ByV al Mailto As String, _

ByVal MailFrom As String, _

ByVal Subject As String, _

ByVal Body As String, _

Optional ByVal MailAttachments As String = "", _

Optional ByVal MailCC As String = "", _

Optional ByVal MailBcc As String = "", _

Optional ByVal ServerName As String = "localhost" , _

Optional ByVal UserLogin As String = "", _

Optional ByVal Password As String = "")

'The mail attachments string should contain semi colon delimited full
pathnames

'of the files to be attached.

Try

Dim mailMsg As New MailMessage

With mailMsg

.From = MailFrom

.To = Mailto

.Cc = MailCC

.Bcc = MailBcc

.Subject = Subject

.Body = Body

.Priority = MailPriority.Hi gh

End With

Dim AttachItem As String

If MailAttachments <"" Then

Dim delimStr As String = ";"

Dim delimiter As Char() = delimStr.ToChar Array()

Dim split As String() = Nothing

split = MailAttachments .Split(delimite r)

For Each AttachItem In split

Dim attachment As New MailAttachment( AttachItem) 'create the attachment
for the message

mailMsg.Attach ments.Add(attac hment) 'add the attachment

Next AttachItem

End If

If ServerName <"localhost" Then

mailMsg.Fields .Add("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1") 'basic authentication

mailMsg.Fields .Add("http://schemas.microso ft.com/cdo/configuration/sendusername",
UserLogin) 'Login name

mailMsg.Fields .Add("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"Password") 'set your password here

End If

SmtpMail.SmtpS erver = ServerName

SmtpMail.Send( mailMsg)

Catch ex As Exception

WriteLogEntry( "Applicatio n", "WebMailing ", "Web mail send error " &
ex.InnerExcept ion.Message, EventLogEntryTy pe.Error, 0, 0)

End Try

End Sub

End Class

The code works OK except when I try to use the attachments. The project
needs to work on a Windows XP Pro or Windows 2000 workstation, it is not
intended for a 2003 server. I know that in 2005 the mailing has been
moved to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses
system.web.mai l.
I found some info and code samples at
http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work
and I need it, badly.

Bob

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******* *********@TK2MS FTNGP04.phx.gbl ...
>>Robert,

It depends how you sent the email. If you use the default client method,
you cannot use attachment.
If you use SMTP (only on "profession al and 2003 OS") than you can use
SMTP mail.

So let us know what you are doing?

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ey****** ********@TK2MSF TNGP04.phx.gbl. ..
I am trying to use framework 1.1 - stuck with it. to send emails from a
windows form application. The email messages can have attachments,
usually two and they can be either text or sounds (wav files) or images
(bmp, gif or tiff)

I can send the email messages OK but the attachments are giving me
grief.

Can anyone provide some code that adds attachments to web mail
messages.

Thanks for any help,
Bob





Dec 1 '06 #5
Bob,

That sounds very strange to me and looks just like a firewall or
virusscanner problem, as there are often in this situations.

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:OS******** ******@TK2MSFTN GP06.phx.gbl...
Cor
I looked at that site and that's where I picked up on how to do it. I did
some more testing with my code and I found that the attachments work OK
when I use localhost (i.e the built-in SMTP server that gets installed
with IIS). But I find that if I try to use an outside mail server like
mail.mycompany. com which is outside my LAN and requires a logon user name
and password, then I can't send mail messages to which I try to attach
files using my code, however if I don't try to use attachments the mail
message gets sent OK. It seems to mean that somehow one needs to do some
other code when trying to make attachments to a remote server. I could not
find any documentation or sample code on that specific problem.

Regards,
Bob
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:OV******** ******@TK2MSFTN GP02.phx.gbl...
>Robert,

The first thing I thought on was "Is Robert using HTML post, because that
preservers the charachters"
Almost nobody likes that but as you have to do that, than you have no
alternatives .

At the moment I don't have the time to check your code but this is the
best website with information about your problem. If nobody else is
checking your code and you keeps the problem, than please reply I can
than see if I have the time to check it in the weekend.

http://www.systemwebmail.net/

Cor
.


"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ug******* *******@TK2MSFT NGP02.phx.gbl.. .
>>Cor this is the snippet of code that I use so far,
Imports System.Web.Mail

Public Class clsWebMail

Public Sub SendWebMail(ByV al Mailto As String, _

ByVal MailFrom As String, _

ByVal Subject As String, _

ByVal Body As String, _

Optional ByVal MailAttachments As String = "", _

Optional ByVal MailCC As String = "", _

Optional ByVal MailBcc As String = "", _

Optional ByVal ServerName As String = "localhost" , _

Optional ByVal UserLogin As String = "", _

Optional ByVal Password As String = "")

'The mail attachments string should contain semi colon delimited full
pathnames

'of the files to be attached.

Try

Dim mailMsg As New MailMessage

With mailMsg

.From = MailFrom

.To = Mailto

.Cc = MailCC

.Bcc = MailBcc

.Subject = Subject

.Body = Body

.Priority = MailPriority.Hi gh

End With

Dim AttachItem As String

If MailAttachments <"" Then

Dim delimStr As String = ";"

Dim delimiter As Char() = delimStr.ToChar Array()

Dim split As String() = Nothing

split = MailAttachments .Split(delimite r)

For Each AttachItem In split

Dim attachment As New MailAttachment( AttachItem) 'create the attachment
for the message

mailMsg.Attac hments.Add(atta chment) 'add the attachment

Next AttachItem

End If

If ServerName <"localhost" Then

mailMsg.Field s.Add("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1") 'basic authentication

mailMsg.Field s.Add("http://schemas.microso ft.com/cdo/configuration/sendusername",
UserLogin) 'Login name

mailMsg.Field s.Add("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"Password") 'set your password here

End If

SmtpMail.Smtp Server = ServerName

SmtpMail.Send (mailMsg)

Catch ex As Exception

WriteLogEntry ("Applicatio n", "WebMailing ", "Web mail send error " &
ex.InnerExcep tion.Message, EventLogEntryTy pe.Error, 0, 0)

End Try

End Sub

End Class

The code works OK except when I try to use the attachments. The project
needs to work on a Windows XP Pro or Windows 2000 workstation, it is not
intended for a 2003 server. I know that in 2005 the mailing has been
moved to SYSTEM.NET.MAIL but I'm stuck with using VS2003 that uses
system.web.ma il.
I found some info and code samples at
http://www.systemwebmail.com/faq/2.3.aspx but the attachments don't work
and I need it, badly.

Bob

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2****** **********@TK2M SFTNGP04.phx.gb l...
Robert,

It depends how you sent the email. If you use the default client
method, you cannot use attachment.
If you use SMTP (only on "profession al and 2003 OS") than you can use
SMTP mail.

So let us know what you are doing?

Cor

"Robert Dufour" <bd*****@sgiims .comschreef in bericht
news:ey***** *********@TK2MS FTNGP04.phx.gbl ...
>I am trying to use framework 1.1 - stuck with it. to send emails from a
>windows form application. The email messages can have attachments,
>usually two and they can be either text or sounds (wav files) or images
>(bmp, gif or tiff)
>
I can send the email messages OK but the attachments are giving me
grief.
>
Can anyone provide some code that adds attachments to web mail
messages.
>
Thanks for any help,
Bob
>
>
>




Dec 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2170
by: .: DeVa :. | last post by:
How can i brows for picture on disk and then save it into array for mailing ? ------ www.podvodni-svijet.com "Half-brother in blood, full brother in heart will I be. Thou shalt lead and I will follow. May no new grief divide us."
5
5476
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and replacing it with a button of my own background color and text. The file paths I'd like displayed in a textarea and then the files uploaded at once.
2
2271
by: Marcus | last post by:
I have seen many posts of people with the same problem as me (attached below), but I have yet to see any solutions posted. Has anyone figured out how to deploy an Asp.net web site to the webserver in any place other than the default website? I do not want to install it there as our IIS has multiple websites, but nowhere is there an option when creating the install package in Visual Studio to specify what website on the server you want to...
3
2245
by: Brian Farnhill (MCP VB.NET) | last post by:
Hi, I am having some trouble using the MailMessage object to send an email with more than one attachment. I am working on a web based application where a user can submit information, along with a number of files. The information, including the file is stored in the database, and an email is sent with the information and any files that were submitted are attached. The system works fine when a user makes a submission that has no...
6
4996
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
0
1512
by: wal | last post by:
How does one attach files to emails using libgmail? The following code http://pramode.net/articles/lfy/fuse/4.txt works fine when said files are simple text files, but it failes as soon as the files are wild binary files, even attaching the source of an email in a text file (.eml files) failes. What am I missing here? Any hints? The output I get when attemting to send binary files using the code above is pasted below. have fun,
6
6894
by: Harshpandya | last post by:
Hi all, I am working on the form in which you fill out the whole PHP form and e mail that details to someone. It is working fine. But now i want to send the same form to be sent to different people and user should be able choose the check boxes to whom they want to send e mail to. I write some code simple If else conditions but i think i am making some mistakes. Because when i tried - it is not sending them e mails. Here is my code. I...
3
5953
by: zaxxon25 | last post by:
I am having an issue with attaching 2 attachments one xip and other excel file with email and sending using perl sendmail. I tried to look on various forums and everywhere i get advice using MIME :: Lite. Unfortunately i cannot use it . I have tried to write a program on my own to send 2 attachments and sending using perl sendmail but program is not working. It is reading only first file for attachment purposes and ignores second one.I would...
1
3207
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the code for attachment, I am not able to send anything. I get blank email. Can you please help me on this? Here is the html form:
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.