Email from windows form

jjjamie

Freshman
Joined
Aug 30, 2002
Messages
34
Location
England
I wonder if anyone can help me. I am trying to send email from a windows form application and I can't work out how to send attachments. How does everyone else do it? I'm comunicating directly with the SMTP server. Is there an easier way?
 
This snippet in the Code Library shows how to accomplish the
feat in VB6. If you can understand the concept and how it works,
you should be able to apply it to VB.NET.

[edit]My "b", use divil's idea instead[/edit]
 
Last edited:
myMailMessage.Attactments.Add(attachment)

Where attachment is an instance of a MailAttachment class.
 
I am getting lots of upgrade warnings and errors when upgrading this code to .NET. Has anyone managed to upgrade this code successfully?
 
That doesn't matter. The Net namespace has nothing to do with
Web applications. The Net namespace provides any application
with the ability to exchange data online, through several means
(sockets, WebClient, etc.)

Just add

Visual Basic:
Imports System.Web.Mail

at the top of your code and you're good to go (or you can type
it minally throughout your code, it doesn't matter).

[edit]Ah-ha, System.Web.Mail... gotcha! :)[/edit]
 
Last edited:
When I said System.Net.Mail what I really meant was System.Web.Mail.

Even so, typing "SMTP" in to the help search box takes you straight there, so nil points for research!
 
Code:
   Sub mailsender(ByVal mailto As String, ByVal msgbody As String, ByVal msgsubj As String, ByVal mailfrom As String, Optional ByVal attachment As String = "")
        Try
Dim Message As New System.Web.Mail.MailMessage()
            Dim attachmentenc As System.Web.Mail.MailAttachment()

            Message.To = mailto
            Message.From = mailfrom
            Message.Body = msgbody
            Message.Subject = msgsubj
            Message.BodyFormat = Web.Mail.MailFormat.Html
            If attachment <> "" Then
                Message.Attachments.Add(attachment)
            End If
            System.Web.Mail.SmtpMail.SmtpServer = "62.105.167.3"
            System.Web.Mail.SmtpMail.Send(Message)
            Message = Nothing
        Catch
            MsgBox("Error Sending Mail")
        End Try
end sub

I cannot to save my life find out how to make the attachment thing work!!!! Please can someone put me right!
 
You are not addind the MailAttachment object (attachmentenc) , you're addind a string in this line:

Visual Basic:
Message.Attachments.Add(attachment)
 
hey that seems like the code i need im gonna use it if u dont mind Leeus, and can i ask do u just call that subroutine and it will send the email?...

and two last quesys

im a n00b wat do u have to specify in the




System.Web.Mail.SmtpMail.SmtpServer = "62.105.167.3"
System.Web.Mail.SmtpMail.Send(Message)
Message = Nothing



i dont get that
 
ok i get it now

but for the smtpserver address ok i mean i have an smtp mail account setup on my system throuhg OE but wat if sum1 doesn have that setup what will they do?... say they were just a normal hotmail user
 
You have to specify your outgoing mail server, just copy yuor settings from Outlook really, bear in mind it needs to be open for relay from your ip, i.e. the server I specified will not work for you!
 
what do u mean it needs to be opened in relay from your ip?

i used my isp smtp server and made just a dummy app and let users test it on other isps
it all worked
i removed my emailaccount from OE and it worked

u wanna try it out on urs


here's the SMTP


mail-hub.bigpond.net.au



if i can find any other ones that are same as these im set


i was wondering is it possible to make a little app that runs as a service which makes ur PC acts like the SMTP.. and using your default IP
 
Back
Top