Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Mail Web Service

Status
Not open for further replies.

ami7

Programmer
Oct 3, 2002
48
GB
Hi,

Is there any example on this forum for creating a webservice for sending mail?

If so please guide me on this.

Thanks in advance,
ami.
 
you mean that your client would send a body message, a sender and a target mail address and the webservice should make and send the mail?
if yes, it's a quite simple web service.

You could create a MyMessage class, containing body, title, sender, reciever attributes.
Then on the client make a instance of this object and send it to your server.
In the server get the object and create a mail
You can send a mail in VB.NET this way (it's only a solution not the only one) :

Code:
    Public Function SendMail(ByVal body As String)
        Dim from As String = Csystem.AppSettings("ExpeditorEmail")
        Dim mailto As String = Csystem.AppSettings("RecipientEmail")
        Dim subject As String = "Application Log - Do not reply"
        SmtpMail.Send(from, mailto, subject, body)
    End Function


Here is the way you declare your webService:

Code:
<System.Web.Services.WebService(Namespace:=&quot;[URL unfurl="true"]http://tempuri.org/&quot;)>[/URL] Public Class SendmyMail
    Inherits System.Web.Services.WebService
    <WebMethod()> Public Function WS_Send(ByVal msg As MyMessage) As String
    'send the mail here
    End Function
End Class

Here is the way you send the request to the server :


Code:
Dim wsTest As New SendmyMail()
Dim myObj as MyMessage
myObj.sender= .....
...
strReponse = wsTest.WS_Send(myObj)

Best regards,
Elise, XML learning girl X-)
 
Hi,

Thanks for you info,
Wat i want is to create a webservice which calls a function and the function should have the code for sending email to the id which is mentioned in the TO address.

am trying this but nothing happens:

I created a webservice like this.
<WebMethod()> Public Function SendMail() As DataSet

Dim m As New System.Web.Mail.MailMessage()
With m
.From = &quot;me@my.place&quot;
.To = &quot;xyz@org.uk&quot;
.Subject = &quot;My SMTP Test&quot;
.Body = &quot;My New Message&quot;
System.Web.Mail.SmtpMail.Send(m)
End With

I am not sure if this is right...DO i have to mention anything about the smtp server name or so...
Not good at mail server stuff...please help.

thanks.
ami.
 
no you don't have to set anything.
are you sure that the webservice method is called ? (debug mode)
why do you return a dataset ?
as you can see in the help of .net your syntax is correct
So i think that you don't call correctly the webservice.
First, you should create a simple application with a button that executes your method, to be sure that the syntax for the sendmail is correct.
Then if the method is correct, the problem in on the webservice call side.
Did you created a webservice class before the method ? did you check that the client calls the server ? use the debug mode step by step i'm sure you will find the answer








.net help about Send()
Dim myMail As New MailMessage()
myMail.From = &quot;from@microsoft.com&quot;
myMail.To = &quot;to@microsoft.com&quot;
myMail.Subject = &quot;UtilMailMessage001&quot;
myMail.Priority = MailPriority.Low
myMail.BodyFormat = MailFormat.Html
myMail.Body = &quot;<html><body>UtilMailMessage001 - success</body></html>&quot;
SmtpMail.Send(myMail)
Best regards,
Elise, XML girl X-)
 
Hi Elise,

i created one button and a text box in my form(.aspx page).
In the click event of the button am using the foll code.

still nothing happens:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NewMessage As New System.Web.Mail.MailMessage()
NewMessage.To = &quot;xyz@org.uk&quot;
NewMessage.From = &quot;webserver@here.com&quot;
NewMessage.Subject = &quot;New information submitted&quot;
NewMessage.Body = txtBody.Text
SmtpMail.send(NewMessage)
End Sub

wat is wrong in the above code.
In few other examples there is this line which is included.
'System.Web.Mail.SmtpMail.SmtpServer = &quot;NYMPH&quot;
why do we need this???

Thanks for your help.
ami.
 
well
i have never specified the mail server. This class (smtpmail) allow you to avoid to specify a server.
I don't know the way the connection is set on your computer.
Did you catch an exception ? (try catch)
Is your computer connected to a lan internet access ?
Try a more simple way to send the mail :
SmtpMail.send(&quot;a@a.com&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;)
Best regards,
Elise, XML girl X-)
 
hi,
I tried by just specifying

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

SmtpMail.Send(&quot;sukhi.venkatesh@edexcel.org.uk&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;)
End Sub

no errors.
am cheking my mail in outlook...nothing is there..

any clues??

thanks,
ami
 
Hi ami
I wrote an FAQ on this a while back hopefully this can help you
faq796-2119 That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top