本文介绍了使用asp.net和C#发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试使用asp.net和c#发送电子邮件,但它显示发送电子邮件失败。
i拥有域名.ca
重要。
谢谢
Naveen
Hi all,
I am trying to send email using asp.net and c#, but it shows failure sending email.
i have the domain with .ca
Does it matter.
Thanks
Naveen
推荐答案
Public Function SendMail(sender As Object, e As EventArgs) As String
Dim retVal As String = Nothing
Dim urlURI As String = HttpContext.Current.Request.Url.AbsoluteUri
Dim urlPath As String = HttpContext.Current.Request.Url.AbsolutePath
Dim myServerName As String = Strings.Left(urlURI, urlURI.Length - urlPath.Length)
Dim clientMail As String = ' This is your client e-mail
Dim myCred As Net.NetworkCredential = New Net.NetworkCredential
Dim MailConf As New Net.Mail.SmtpPermissionAttribute(System.Security.Permissions.SecurityAction.Assert)
myCred.Domain = 'here is you mail Domain... your domain
myCred.Password = ' here is the password from the above account
myCred.UserName = ' here is an account on your mail server on which you'll Logged in
Dim myGuid As String = 'If you want to reply in this mail then put his Guid record from SQL server
'Create a new MailMessage object and specify the"From" and "To" addresses
Dim Email As New System.Net.Mail.MailMessage(myCred.UserName, clientMail)
Email.Subject = "Verification Mail from ......."
Dim messageString As String = 'Your Message string on the e-mail body
Email.Body = messageString
Dim mailClient As New System.Net.Mail.SmtpClient()
'This object stores the authentication values
Dim basicAuthenticationInfo As _
New System.Net.NetworkCredential(myCred.UserName, myCred.Password)
mailClient.Host = myCred.Domain
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)
reader.Dispose()
Return retVal
End Function
嗯这是我在发送电子邮件问题上的建议
Well that's my propose in your issue with sending e-mail
private void SendNotification ( string message, string reciever )
{
string userName = "[email protected]"; //insert the usernme for the mail account
string passWord = "yourPassword"; //insert corrosponding password
string fromText = "[email protected]"; //Whatever to identify the Sender
string toText = receiver;
string subjectText = "e-mail header text";
string bodyText = "email body text"
SmtpClient smtpClient = new SmtpClient ( "smtp.gmail.com", 587 );
smtpClient.EnableSsl = true;
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential ( userName, passWord );
MailMessage mail = new MailMessage ( fromText, toText, subjectText, bodyText );
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
smtpClient.Send ( mail );
}
public void GetMail()
{
NetworkCredential cred = new NetworkCredential("[email protected]", "Password");
MailMessage msg = new MailMessage();
msg.To.Add("[email protected]");
msg.Subject = "Welcome";
msg.Body = "You Have Successfully sent mail!!!";
msg.From = new MailAddress("[email protected]"); // Your Email Id
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
SmtpClient client1 = new SmtpClient("smtp.mail.yahoo.com", 465);
client.Credentials = cred;
client.EnableSsl = true;
client.Send(msg);
}
这篇关于使用asp.net和C#发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!