Advertisement

02.15.2008 at 07:31AM PST, ID: 23166242
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Sending email from .net web page

Asked by najh in WebApplications, .NET, Simple Mail Transfer Protocol (SMTP)

Tags:

I'm trying to send an email from a web page, and I feel a bit lost and thought I'd come here for help, as I've spent enough time trying to get google to help me, now it's time for a human.

I've been provided with some login information for a server which should send email for me. This server info works for an existing website (made using asp classic) and I'm trying to reuse the same mail server for sending mail from my ASP.net page.

So here is a sample of vb code which contains the email server settings I've been provided with: (obviously I've changed them!!)
And it's written in vb unfortunately:

Dim errorMsg
If Len(request.form("Address")) > 1000 Then
errorMsg = ("Sorry, but there are too many characters in your Address, please <a href=""index.asp"" onsubmit=""history.back();return false;"" onclick=""history.back();return false;"">go back</a> and try again.")
Else
For Field = 1 to Request.Form.Count - 4 'number of hidden fields + 1
FieldName = Replace(Request.Form.Key(Field),"_"," ")
FieldValue = Request.Form.Item(Field)
Body = Body & FieldName & ":"& VbCrLf & FieldValue & "" & VbCrLf & VbCrLf
Next
'Dimension variables
Dim objCDOSYSCon
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
'Set and update fields properties
With objCDOSYSCon
'Outgoing SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "111.111.111.111"
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 11
'CDO Port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
'email account details
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "1111@dododo.com"
.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass111"
.Fields.Update
End With
'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
'Set and update email properties
With objCDOSYSMail
'0=Low, 1=Normal, 2=High
.Fields("urn:schemas:httpmail:importance").Value = 1
'Who the e-mail is from
.From = Request.Form("email_address")
'Who the e-mail is sent to
.To = "recipient@somecompany.com"
'Who the e-mail is CC'd to
.Cc = "carbonrecipient@somecompany.com"
'The subject of the e-mail
.Subject = Request.Form("email_subject")
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
.TextBody = Body
.Fields.Update
'Send the e-mail
.Send
End With
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
'Rederect after sending email
Response.Redirect Request.Form("redirect_to")
End If
%>

Now I'd like to be able to use that stuff in my .net / C# web application. I've got a book... and here's what my book has made me do so far in my C# page:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class mail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      System.Net.Mail.MailMessage myMessage = new System.Net.Mail.MailMessage("mail1@somecompany.com", "mail2@somecompany.com", "test, please ignore", "test, please ignore");
      System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("111.111.111.111", 11);
      System.Net.Mail.SmtpDeliveryMethod smtpDelMethod = new SmtpDeliveryMethod(
     
      smtp.Send(myMessage);
    }
}


So I don't really see where to add my username and password. Plus I have no idea if it'll work even if i could figure out where to put a username and password.

Please help me to progress a bit!! Am I on the right track? Do I need to change the method i'm using?




Start Free Trial
[+][-]02.15.2008 at 09:10AM PST, ID: 20903703

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: WebApplications, .NET, Simple Mail Transfer Protocol (SMTP)
Tags: C# .net asp.net
Sign Up Now!
Solution Provided By: Arlowin
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.15.2008 at 10:39AM PST, ID: 20904591

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628