MVC :: How To Mock Smtp

May 24, 2010

in one of my controllers, i have an action sending mail. I want to do a unit test on it.

How do i mock the smtp?

View 7 Replies


Similar Messages:

Configuration - Multiple SMTP Servers Or Update The SMTP Object Server Information At Runtime?

Nov 5, 2010

The question: Is it possible to configure multiple SMTP servers or update the SMTP object server information at runtime?

Description of problem: The site I'm working on has a few pages which send emails. Our site is using Gmail so even though it's a custom domain our email is sent out though Gmail SMTP servers.

Some emails come from the system and some emails come from users in certain groups. I have an SMTP server configured with the admin email for the system e.g. admin@mysite.com This works fine and when I get the email it shows from admin@mysite.comOne of our user groups let's call it "groupA" has an email configured on our domain i.e. groupA@mysite.com When I send the email and specify a from address for the MailMessage object as groupA@mysite.com it still shows up in my outlook as coming from admin@mysite.com I did a little further testing and if I specify both the from address and the ReplyTo as groupA@mysite.com it will show as From=admin@mysite.com but when I choose reply in outlook it shows groupA@mysite.com My best guess is that Gmail is overwriting the From address with the SMTP user to prevent email spoofing.

I found this: http://www.systemnetmail.com/faq/4.1.aspx but it won't work for me since group A, B, and C all need to send emails from the same page.

View 1 Replies

Mock 3.5 To Unit Test Web Controls?

Feb 4, 2010

I want to mock ASP.NET 3.5 behavior in order to unit test my WebControls: I want to test how they perform with mock data with existing system of events. Basically I want to test generated result HTML based on input mock data. How to do it? I looked into NMock, but it doesn't suit my needs for 2 reasons:

It just runs ASP.NET server in separate process in order to get resulting HTML; My WebControls output HTML as a text on render, so there are elements which do not correspond to any ASP.NET control (except LiteralControl in some cases). Also, I have huge legacy system, so rewriting everything for MVC won't work for me (too much job), I need to write unit tests to existing controls.

View 1 Replies

Unit Testing - How To Mock A Model In MVC

Nov 11, 2010

I've made a custom model, and I want to mock it. I'm fairly new to MVC, and very new to unit testing. Most approaches I've seen create an interface for the class and then make a mock that implements the same interface. However I can't seem to get this to work when actually passing the interface into the View. Cue "simplified" example:

[code]...

Upon a HttpPost I get a "Cannot create an instance of an interface" exception. I seems that I can't have my cake (passing a model) and eat it (pass mock for unit testing). Maybe there's a better approach to unit testing models bound to views?

View 3 Replies

Creating A Mock URL Referrer In MVC For Unit Testing?

Feb 10, 2010

I'm currently testing my application and am stuck on trying to figure out how to create a custom fake URL referrer. I've tried to hard code it, but am getting an error that it is read-only. Here is what I've tried so far:

fakeController.HttpContext.Request.UrlReferrer.AbsolutePath = "http://www.yahoo.com";
as well as,
fakeController.Request.UrlReferrer = "http://www.yahoo.com";

I've searched the web for some ideas on how to create a fake/mock URL referrer for my fake controller, but have had no luck.

Note: I'm using Visual Studios built-in unit testing facilities.

UPDATE:

I would be more than willing to use any other unit testing system outside of Visual Studio, unfortunately here at my work we are only allowed to use Visual Studio's built-in system, so I gotta work with what I've got.

View 3 Replies

Unit Testing / Mocking HttpContext Without Using Any Mock Framework

Sep 7, 2010

Since I'm having problem with unit testing RenderPartialViewToString() with Moq framework [URL] I'm thinking about getting my controller directly, without using Moq for these particular test, however, how do I mocks (or set) the HttpContext for my test without using any Moq framework?

I need to able to do something similar to this, without Moq of course:

var mockHttpContext = new Mock<ControllerContext>();
mockHttpContext.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("n1\test");
mockHttpContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

View 2 Replies

Architecture :: Unit Testing Delegates With Mock Framework?

Apr 3, 2011

I'm using the mock framework to unit test some methods. I came across some methods that use delegates. I did not find a way to setup these delegates to return the objects that I want. The mock framework does not support it as far as I know. Is this supported in other mock frameworks like nMock?

View 3 Replies

Mock Server.HtmlEncode - Returns Null Reference?

Nov 16, 2010

I'm trying to mock Server.HtmlEncode(), but I keep having a null reference exception.I'm pretty new to the Moq framework, here is my code:

var context = new Mock<HttpContextBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
server.Setup(svr => svr.HtmlEncode(It.IsAny<string>())).Returns((string s) => s);
context.Setup(ctx => ctx.Request).Returns(request.Object);
context.Setup(ctx => ctx.Response).Returns(response.Object);
context.Setup(ctx => ctx.Session).Returns(session.Object);
context.Setup(ctx => ctx.Server).Returns(server.Object);

I've also tried the following:

context.Setup(ctx => ctx.Server.HtmlEncode(It.IsAny<string>())).Returns((string s) => s);

I've found a solution but it seems an outdated solution as expect is replaced with setup.

View 2 Replies

C# - Mock MVC Site, An Outline For Coders To See Functionality And To Start Coding?

Oct 20, 2010

I have to setup an MVC project to house all the HTML documents. This would be like a hierarchical structure using routing. The pages don't have to function, just act as placeholders. It's really just for the group to see all the HTML Pages to get an Idea of functionality. Then we would back fill groups of pages with the functionality by creating the controllers, model etc. How would this be best accomplished? Are there mock frameworks that could accomplish this? So it would be a project just having views, with a control ler that allows navigation between pages, simple to show mostly static HTML pages. The idea is simply for the group to see all the functionality, and to put together a structure to start coding. If possible we would like to see the correct URL based on the route table. What would be a quick solution for this while we work on the back end Object/Domain model?

View 1 Replies

Processing SMTP Bounces With .net?

Feb 17, 2010

Am looking for examples specific to .net/mvc and servers native WinServer08 where problem being addressed is processing a bounced smtp msg so as to bind to an estore transaction and updating account/profile properties.

Reading the related questions i find an interesting reference to [VERP]2. Under the heading 'Software that supports VERP i find that IIS is not on the list. Does that mean i need to find a library to integrate into my store's assembly?

What resources do I have to pull together to make sure that the webapp is informed when mail bounces? fwiw - i'm working with a very low volume site.

View 1 Replies

Web Forms :: Using Localhost In SMTP, Asp.net 2.0

Jan 25, 2011

Im trying to follow the directions within this page to configure my smtp server, I have windows 7 and iis 7.

http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/f73a7f0f-a17c-4a48-a42c-8da8e36f6cc6/

Im having issues with the code behind:

System.Net.Mail.SmtpClient SmtpMail = new System.Net.Mail.SmtpClient();

////////////////Below 4 lines are for testing in windows 7. Comment them before compiling for production.//////////////

////////////////Host and DeliveryMethod are set for SMTP4Dev.exe to receive the mail//////////////

SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
SmtpMail.PickupDirectoryLocation
= "C:\inetpub\mailroot\Pickup";
SmtpMail.Host = "127.0.0.1"; // localhost
SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

Is this suppose to be in the code behind page of the password recovery page? or in a separate class? When pasting in the code behind I get an error under the word system and smtpmail? Do I need to include an imports statement: imports system.net.mail?

View 4 Replies

Setting SMTP On IIS Express?

Jan 25, 2011

setting up my SMTP on IIS Express?

View 1 Replies

Configuring SMTP Server In IIS?

Dec 21, 2010

I am trying to get the SMTP Server in IIS7 working so I can use the asp:PasswordRecovery component. I have included a screenshot of my SMTP setup in IIS, the SMTP setup in my web.config file, and my asp:PasswordRecovery component code. I have set it up to not require any authentication settings. I basically want to specify whatever email address I want as the "From" attribute (I'm using a series of noreply* addresses for a web app), like the php mail function that lets you put whatever you want in the from argument. What am I missing? Do I need to install anything else? I'm assuming that when people say "you need an SMTP server to send mail", this is what they're talking about.

Web.config:

[Code]....

ASP Code:

[Code]....

SMTP Setup Screenshot:

View 6 Replies

Send This Form Using SMTP And VB.NET?

Jan 18, 2011

My code was .... But it only send one field value to email .... I want multiple values to be send as it is in mail ... like ..

Category :
Your name :
Email ID
Mobile no. etc..

All form values will be transferred to mail ID ...

Imports System.Net.Mail
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential("bus@volvobusesindia.com", "pink&777")
SmtpServer.Port = 25
SmtpServer.Host = "mail.volvobusesindia.com"
mail = New MailMessage()
mail.From = New MailAddress(TextBox12.Text)
mail.To.Add("bus@volvobusesindia.com")
mail.Subject = "New Bus Booking Query"
mail.Body = "Category :" & " " & DropDownList3.SelectedItem.Text
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

View 1 Replies

Sample About Instruction SMTP?

Nov 13, 2010

I want good sample about instruction SMTP

View 3 Replies

Sending Email Using Smtp?

Apr 11, 2010

I can find loads of posts about codes to send emails using smtp, but I've got a problem. I want to send a registration mail to a user that has made a new account on my site, so he can activate it by clicking on a link in the mail. Only problem is: I need to use an smtpserver but I don't know which smtpserver i can use, so the mail is never sent!

[Code]....

This is my code below:

the code of the aspx page:
[Code]....

My web.config:
[Code]....

View 14 Replies

Using SMTP Credentials For WebMail?

Dec 31, 2011

Is it possible to use credentials from a Webmail account such as Yahoo, Mail, Techemail, etc. for sending emails from within my webpage? I have a webmail account with Techemail.com and Yahoo. Instead of using my hosting SMTP credentials, I wish to use Techemails or Yahoos. I found an example using Yahoo's SMTP/POP information and tried to emulate it in my webpage but I keep getting the "Failure sending mail" error. Not sure what I'm doing wrong. Here is my code below.

Imports System.Net.Mail
Private Sub FormatEmail()
Try
Dim [to] As String = txtEmailAddress.Text
Dim [from] As String = "myEmail@techemail.com"

[Code] ....

View 2 Replies

How To Send Email Without Smtp Server

May 11, 2010

I want to send email without declare username and password in smtp server. I am using asp.net c#, this is possible in asp below is the code , anybody tell me how can i use this code in asp.net.

<%
Dim ObjSendMail
Dim iConf
Dim Flds
Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")....

View 5 Replies

Reading SMTP LogFile From Code?

Nov 27, 2010

Is there a way to read the error message from the SMTP log files so that to indicate to the user that we are unable to send them email for any reason?

View 1 Replies

Check SMTP Host Status?

Nov 16, 2010

Is there a way to check smtp host status in ASP.NET.

View 1 Replies

C# - How To Get The SMTP Settings Automatically From Web.config

May 4, 2010

I noticed that we always just are like:

SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
mSmtpClient.Send(mMailMessage);

And the only place the credentials are set are in web.config:

<system.net>
<mailSettings>
<smtp>
<network host="xxx.xx.xxx.229" userName="xxxxxxxx" password="xxxxxxxx"/>
</smtp>
</mailSettings>
</system.net>

So my question is, how does it automagically get them out?

View 3 Replies

Web Forms :: How To Know The Details Of Mail Sent Using Smtp

Mar 10, 2010

I am sending mails in my application. How do i know whether the receipient has opened or deleted that mail?

View 2 Replies

How To Send Mail In .net Without Smtp Details

May 24, 2010

I have deployed my application on the server and now I come to know that my server would not provide me SMTP detail , is their any way I could send sms without smtp details.I can use bot asp.net3.5 with C# or SQL Server 2005 to send mail.

View 3 Replies

Accessing An Email Attachment In IIS SMTP?

May 6, 2010

Does anyone know a way I can programatically access an email and any attachment for emails sitting in the IIS SMTP queues using .NET?

View 1 Replies

SMTP Email Delete File C#?

Oct 15, 2010

I have a ASP.Net website in which an email has to be sent to user with an excel attached if the user requests.

The user provides the email address, when click on a button to send report, an excel report with the result set should be attached to the email and sent to user.

The excel report will be saved on the server and through SMTP, I'm senidng the report in email. After the email is sent I should delete the excel file created on the server.When I'm trying to delete I get the error, the file is being used by SMTP object (other process).

Is there a way that I can delete this file after the email is sent?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved