| |

VerySource

 Forgot password?
 Register
Search
View: 780|Reply: 5

send email

[Copy link]

3

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-15 10:30:01
| Show all posts |Read mode
private void btnSend_Click (object sender, System.EventArgs e)
{
MailMessage mailMsg = new MailMessage ();
mailMsg.To = txtTo.Text;
mailMsg.From = txtFrom.Text;
mailMsg.From = this.txtsubject.Text;
mailMsg.Body = txtMsg.Text;
mailMsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mailMsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "soundblas@163.com");
mailMsg.Fields.Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "6311455");
try
{
SmtpMail.SmtpServer = "smtp.163.com";
SmtpMail.Send (mailMsg);
Response.Write ("ok");
}
catch (Exception ex)
{
Response.Write ("false;");
}

}
}
Excuse me, it is exactly the same as the one written in the book. The book says that I can send e-mails. Why I am FALSE after running, I hope to guide me how to write
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-6-13 07:15:02
| Show all posts
Maybe the mail server has changed!
Reply

Use magic Report

2

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-6-16 15:45:01
| Show all posts
mailMsg.To cannot be assigned directly, only

MailMessage mailMsg=new MailMessage(from,to);

As for the latter part of smtp certification, it seems that it will not be used in 2015, I set it in web.config
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-6-17 18:30:01
| Show all posts
Throw out your error type, what exactly is the error?
Reply

Use magic Report

0

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-7-7 08:45:01
| Show all posts
Most of the examples in the book about sending emails cannot be realized, they are all misleading and disgusting.
The examples in the book generally call System.Web.Mail, which itself is relatively outdated,
System.Net.Mail is generally used under vs. In addition, you use this method,
See if your IIS installed smtp virtual service
Not in the company right now, if you need to wait and send me a message, I will send you a successful example
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-7 10:00:01
| Show all posts
1. Check if the SMTP server in your IIS is installed!
2. The errors in the book are normal and they are not responsible. Search the code online!
3.using System;
using System.Web;

namespace EMailCommon
{
/// <summary>
/// Summary description for CDOSendMail.
/// </summary>
public class CDOSendMail
{
public CDOSendMail()
{
//
// TODO: Add constructor logic here
//
}
The
public static void sendMail(string mailFrom, string mailTo, string mailSubject, string mailBody)
{
try
{
CDO.Message oMsg = new CDO.Message();
   
oMsg.From = mailFrom;
oMsg.To = mailTo;
oMsg.Subject = mailSubject; // "MailTest";
                 
oMsg.HTMLBody = mailBody;



CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
         
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value= mailFrom; //"dhou@sagatechnologies.com"; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value= mailTo; //"dhou@sagatechnologies.com"; //email account
//oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="XXXXX@XXXXXX.com";
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = System.Configuration.ConfigurationSettings.AppSettings["sendusername"];
//oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="3308576636";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = System.Configuration.ConfigurationSettings.AppSettings["sendpassword"];
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 represents Anonymous verification method (no verification required)
//value=1 represents Basic authentication method (use basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
//Value=2 stands for NTLM authentication method (Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
//oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value= "smtp.fabby.com";
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value= System.Configuration.ConfigurationSettings.AppSettings["smtpserver"];
//"smtp.21cn.com";



oFields.Update();
oMsg.BodyPart.Charset="ISO-8859-1";
oMsg.HTMLBodyPart.Charset="ISO-8859-1";



oMsg.Send();
oMsg = null;
}
catch (Exception e)
{
throw e;
}
}
}
}
for reference!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list