I'm trying to save my email in a local directory.
This is my code present in the web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
</smtp>
</mailSettings>
</system.net>
I don't get errors but the mail is not present in the directory specified. It is possible that the mail ends up in a (spam)filter?
I suspect the fact that you have both a <network> and a <specifiedPickupDirectory> element in there is the problem. Remove the <network>.
Here's a working example:
web.config
<system.net>
<mailSettings>
<smtp from="HelloWorld#yourdomain.com" deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\dcs\smtp" />
</smtp>
</mailSettings>
</system.net>
Code behind (VB):
Protected Sub startMailing(sender As Object, e As EventArgs) Handles Button2.Click
Dim msg As New System.Net.Mail.MailMessage()
Dim smtpSrvr As New SmtpClient
msg.To.Add("wylie#acme.com")
msg.Subject = "Fish Goes paddling Down the stream."
msg.Body = "Row Row Row Row"
smtpSrvr.Send(msg)
End Sub
Related
In my Web.Config I have the following
<configuration>
<configSections>
/*some code*/
</configSections>
<appSettings>
<add key="KeyName" value="KeyValue"/>
</appSettings>
</configuration>
And I have used below code when deploying a web application project.
{
"QA": {
"ConfigChanges": [
{
"KeyName": "/configuration/appSettings/add[#key='KeyName']",
"Attribute": "value",
"Value": "NewKeyValue"
}
]
}
}
Above code finds the configuration with appkey name and overwrites it.
But how do we configure if it doesn't have any key, like smtp settings?
<system.net>
<mailSettings>
<smtp from="" deliveryMethod="Network">
<network host="smtp.gmail.com" port="57" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
I tried like below like using key, but I got the error.
{
"KeyName":"/configuration/system.net/mailSettings/smtp/network[#defaultCredentials='true']",
"Attribute": "host",
"Value": "test.com"
}
Failure while updating port of /configuration/system.net/mailSettings/smtp/network[#defaultCredentials='true']: 25
Can you please help me on this.
I have a asp.net website which calculates average and standard deviation using custom timestamps query in the code behind and store results in excel file. But whenever I click to select the longer timeframe it shoots this error. Code behind is as follows :-
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
GridView6.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.[End]()
End Sub
Are there any changes required from the IIS point of view?
I have also added the following tag in the Web.config file but it is giving me the same error.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
In the web.config file added the following lines
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="104857600" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
I am trying to send peroidic emails with Quartz.net but with no success. Firstly, the email code portion below is verified to work as I opened a new project to test it out. When I opened the application.log, I can see the Log.DebugFormat messages and not exceptions was catched, however no email was being sent out. Any advice? Thanks.
public void Execute(IJobExecutionContext context)
{
try
{
Log.DebugFormat("{0}****{0}Job {1} fired # {2} next scheduled for {3}{0}***{0} Fired by {4}",
Environment.NewLine,
context.JobDetail.Key,
context.FireTimeUtc.Value.ToString("r"),
context.NextFireTimeUtc.Value.ToString("r"),
"James");
Log.DebugFormat("{0}***{0}Hello World!!!{0}***{0}", Environment.NewLine);
// Try send email
var mail = new Email();
mail.IsBodyHtml = true;
mail.MailAddresses = "ong1980#hotmail.com";
mail.MailSubject = "Test Cron Job";
var mailMessage = mail.CreateMailMessage();
var Th = new Thread(() => Email.Send(mailMessage, 6, 3000, true));
Th.Start();
}
catch (Exception ex)
{
Log.DebugFormat("{0}***{0}Failed: {1}{0}***{0}", Environment.NewLine, ex.Message);
}
}
App.Config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler,
System, Version=1.0.5000.0,Culture=neutral,
PublicKeyToken=b77a5c561934e089"/>
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="ServerScheduler"/>
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/>
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
</quartz>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="xxx#hotmail.com">
<network host="smtp.live.com" port="25" userName="xxx#hotmail.com" password="xxxxxxxxx" />
</smtp>
</mailSettings>
</system.net>
</configuration>
Ok happen that inside the /Quartz.Net/Quartz.Server.exe.config which should reside in the program files(x86), I miss out the connectionstring and mailsettings. Hope it can be a help for someone else.
I am trying to set two smtp servers in web.config file but get error
Unrecognized configuration section system.net/mailSettings/smtp_1.
How correctly to do that?
<configuration>
<configSections>
<sectionGroup name="mailSettings">
<section name="smtp_1" type="System.Net.Configuration.SmtpSection"/>
<section name="smtp_2" type="System.Net.Configuration.SmtpSection"/>
</sectionGroup>
</configSections>
<system.net>
<mailSettings>
<smtp_1 from="no-reply1#web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
<network host="smtp...." enableSsl="true" userName="..." password="..." port="587" />
</smtp_1>
<smtp_2 from="no-reply2#web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
<network host="smtp...." port="25" />
</smtp_2>
</mailSettings>
</system.net>
</configuration>
MailSettings is not intended for this purpouse: this section is the place in configuration where you can store SMTP params, so you won't need to change them programmatically when you create a new SmtpClient.
If you want you can create your own section but not change the original one, like this:
<configuration>
<configSections>
<sectionGroup name="myMailSettings">
<section name="smtp_1" type="System.Net.Configuration.SmtpSection"/>
<section name="smtp_2" type="System.Net.Configuration.SmtpSection"/>
</sectionGroup>
</configSections>
<myMailSettings>
<smtp_1 from="no-reply1#web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
<network host="smtp...." enableSsl="true" userName="..." password="..." port="587" />
</smtp_1>
<smtp_2 from="no-reply2#web2pdfconvert.com" deliveryMethod="specifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\Users\Administrator\Projects\temp\wp" />
<network host="smtp...." port="25" />
</smtp_2>
</myMailSettings>
....
and finally don't forget to write some code to use that data!
When using the system.net/mail web.config settings to configure my SmtpClient, it fails to deliver emails, with an "protocol error" described best by Base64 encoding and authentication problems:
Example:
With the following Config
<system.net>
<mailSettings>
<smtp from="email#server.com">
<network host="servermail.outsourced.com"
port="2525"
defaultCredentials="false"
userName="username"
password="password"/>
</smtp>
</mailSettings>
</system.net>
And the Code:
var tmp = new SmtpClient();
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("me#server.com");
msg.To.Add(new MailAddress("me#server.com"));
msg.Body = "test";
tmp.Send(msg);
Produces the error message:
System.Net.Mail.SmtpException: The server committed a protocol violation The server response was: UGFzc3dvcmQ6
at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException
& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
However, in the following code where I manually set all the properties, the code runs without exception and the email is delivered.
var tmp2 = new SmtpClient("servermail.outsourced.com", 2525);
tmp2.Credentials = new NetworkCredential("username", "password");
tmp2.UseDefaultCredentials = false;
MailMessage msg = new MailMessage();
msg.Subject = "test";
msg.From = new MailAddress("me#server.com");
msg.To.Add(new MailAddress("me#server.com"));
msg.Body = "test";
tmp2.Send(msg);
I tried your config settings from within LINQPad against my hMailServer mail server, and they worked great. So, my guess is that the mail server you are communicating with is handshaking with the client in an unexpected fashion. When I was testing, I captured the SMTP log from my server, and here's what it looked like (sanitized, of course):
SENT: 220 my.mailserv.er ESMTP
RECEIVED: EHLO CLIENTAPP
SENT: 250-my.mailserv.er[nl]250-SIZE 25600000[nl]250 AUTH LOGIN
RECEIVED: AUTH login bWFpbHRlc3RAbXkubWFpbHNlcnYuZXI=
SENT: 334 UGFzc3dvcmQ6
RECEIVED: ***
SENT: 235 authenticated.
RECEIVED: MAIL FROM:<mailtest#mailserv.er>
SENT: 250 OK
RECEIVED: RCPT TO:<happyuser#mailserv.er>
SENT: 250 OK
RECEIVED: DATA
SENT: 354 OK, send.
My server requires SMTP AUTH, and you can see that after my client sends the AUTH command, the server responds with status code 334, and the base-64 encoded representation of Password:. So, I'd recommend turning on the trace functionality for the SmtpClient so you can see what is occurring during both scenarios.
I was running LINQPad 4.31, and my linqpad.config file contained:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<mailSettings>
<smtp from="mailtest#mailserv.er">
<network host="my.mailserv.er" port="25" userName="mailtest#mailserv.er" password="supersecure"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
The LINQPad query was as follows:
SmtpClient mailer = new SmtpClient();
Guid g = Guid.NewGuid();
g.Dump("Message GUID");
MailMessage msg = new MailMessage();
msg.Subject = "Test:" + g;
msg.To.Add(new MailAddress("happyuser#mailserv.er"));
msg.Body = "I HAS A BODY";
mailer.Send(msg);
Add this for logging
Please comment what AuthenticationModules are used (you'll find them stated in the network.log).
On my box SmtpLoginAuthenticationModule# is constant used but there are others possible.
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="includehex">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<switches>
<add name="System.Net" value="Verbose"/>
<add name="System.Net.Sockets" value="Verbose"/>
<add name="System.Net.Cache" value="Verbose"/>
</switches>
<sharedListeners>
<add name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="network.log"
/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
Try setting the deliveryMethod attribute to force the configuration to use the network-config
<system.net>
<mailSettings>
<smtp deliveryMethod="network" from="email#server.com">
<network host="servermail.outsourced.com"
port="2525"
defaultCredentials="false"
userName="username"
password="password"/>
</smtp>
</mailSettings>
</system.net>
Guys this code is ok i try using devsmtp for local machine and it work fine
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Using tmp = New SmtpClient()
Dim msg As New MailMessage() With {.Subject = "test", .From = New MailAddress("youremail#domain.com")}
msg.[To].Add(New MailAddress("youremail#domain.com"))
msg.Body = "test"
tmp.Send(msg)
End Using
End Sub
please download the devsmtp for local machine from
http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=smtp4dev&DownloadId=269147&FileTime=129575689693530000&Build=20393