发送邮件显示按摩的问题是发送邮件失败 [英] Problem to sending mail showing massage is failure sending mail

查看:113
本文介绍了发送邮件显示按摩的问题是发送邮件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送邮件显示按摩的问题是发送邮件失败



我尝试过:



MailMessage MyMail = new MailMessage(SendFrom,SendTo);

if(SendTo.Trim()。Length == 0)

抛出新的异常(收件人地址无效。);



MyMail.IsBodyHtml = true;

MyMail.Subject = Subject.Trim();

MyMail.Body = Body.Trim();

System.Net.Mail.Attachment objatt = new Attachment(Attachment);



MyMail.Attachments.Add(objatt);



//制作凭证

//////系统.Net.NetworkCredential mailAuthentication = new

//////System.Net.NetworkCredential(ConfigurationManager.AppSettings[\"smtpUser1],ConfigurationManager.AppSettings [smtpPassword1]);

//////System.Net.Mail.SmtpClient smtpHost = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings [smtp],(Convert.ToInt32(ConfigurationManager.AppSettings [smtpPort])));

System.Net.NetworkCredential mailAuthentication = new

System.Net.NetworkCredential(ConfigurationManager.AppSettings [smtpUser],ConfigurationManager.AppSettings [smtpPassword]);

System.Net.Mail.SmtpClient smtpHost = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings [smtp],(Convert.ToInt32(ConfigurationManager.AppSettings [smtpPort]))) ;



//启用SSL

smtpHost.EnableSsl = true;

smtpHost.UseDefaultCredentials = false;

smtpHost.Credentials = mailAuthentication;

smtpHost.Timeout = 200000;

smtpHost.Send(MyMail);

这鳕鱼e在dll中使用。

------------------------------------- --------------------------

< add key =XmlDirvalue =XML>

< add key =smtpUservalue =support@pointindia.co.in>

< add key =smtpPasswordvalue =password> ;

< add key =smtpvalue =smtp.gmail.com>

< add key =smtpPortvalue =465>

< add key =CrystalImageCleaner-AutoStartvalue =true>

< add key =CrystalImageCleaner-Sleepvalue =60000>

< add key =CrystalImageCleaner-Agevalue =120000>



此代码usimg in web.config

-------------------------------------------- ---------------------

和错误按摩显示发送邮件失败。

problem to sending mail showing massage is failure sending mail

What I have tried:

MailMessage MyMail = new MailMessage(SendFrom, SendTo);
if (SendTo.Trim().Length == 0)
throw new Exception("Invalid receiver address.");

MyMail.IsBodyHtml = true;
MyMail.Subject = Subject.Trim();
MyMail.Body = Body.Trim();
System.Net.Mail.Attachment objatt = new Attachment(Attachment);

MyMail.Attachments.Add(objatt);

// Making Credential
//////System.Net.NetworkCredential mailAuthentication = new
//////System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser1"], ConfigurationManager.AppSettings["smtpPassword1"]);
//////System.Net.Mail.SmtpClient smtpHost = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtp"], (Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"])));
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"], ConfigurationManager.AppSettings["smtpPassword"]);
System.Net.Mail.SmtpClient smtpHost = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtp"], (Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"])));

// Enabling SSL
smtpHost.EnableSsl = true;
smtpHost.UseDefaultCredentials = false;
smtpHost.Credentials = mailAuthentication;
smtpHost.Timeout = 200000;
smtpHost.Send(MyMail);
this code using in dll.
---------------------------------------------------------------
<add key="XmlDir" value="XML">
<add key="smtpUser" value="support@pointindia.co.in">
<add key="smtpPassword" value="password">
<add key="smtp" value="smtp.gmail.com">
<add key="smtpPort" value="465">
<add key="CrystalImageCleaner-AutoStart" value="true">
<add key="CrystalImageCleaner-Sleep" value="60000">
<add key="CrystalImageCleaner-Age" value="120000">

this code usimg in web.config
-----------------------------------------------------------------
and error massage show Failure sending mail.

推荐答案

使用此C#类 -



Use this C# class -

   using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using System.Data.OleDb;


namespace _1079541_Problem_to_sending_mail_showing_massage_
{
    class Mail
    {
        public static string Profile;
        public static string FromEmail;
        public static string FromName;
        public static string FromPassword;
        public static string SMTP_Host;
        public static int SMTP_Port;
        public static Boolean SMTP_EnableSSL;
        public static string Subject;
        public static string EmailBody;

        public static string SendMail(string mailToEmail, string mailToName, string attachments)
        {
            //LoadMailSetting
            Profile = "Gmail Mail";
            FromEmail = "EmailFrom@GMAIL.COM";
            FromName = "Test Mail";
            FromPassword = "MyPassword";
            SMTP_Host = "smtp.gmail.com";
            SMTP_Port = 587;
            SMTP_EnableSSL = Boolean.Parse("True"); ;
            Subject = "Test Email";
            EmailBody = "Test Email";

            Attachment attachment = new Attachment(attachments.ToString()); //create the attachment
            try
            {

                MailMessage mail = new MailMessage();
                // set the addresses
                mail.From = new MailAddress(FromEmail.ToString());

                mail.To.Add(new MailAddress(mailToEmail.ToString()));

                // set the content
                mail.Subject = Subject.ToString();
                mail.Body = EmailBody.ToString();
                SmtpClient smtp = new SmtpClient(SMTP_Host.ToString(), SMTP_Port);
                smtp.Credentials = new NetworkCredential(FromEmail.ToString(), FromPassword.ToString());
                smtp.EnableSsl = true;
                mail.Attachments.Add(attachment);
                smtp.Send(mail);
                //MessageBox.Show("Mail Sent");
                return "";
            }
            catch (Exception ex)
            {

                return ex.Message.ToString(); // Profile.ToString() & "-" & FromEmail & "_" & FromName & "_" & FromPassword & "_" & SMTP_Host & "_" & SMTP_Port & "_" & SMTP_EnableSSL & "_" & Subject & "_" & EmailBody;
            }
        }
    }
}





你可以使用如下所示的类 - 调用发送邮件方法



You can use this class as below - Call the send mail method

string msg;
msg=Mail.SendMail("ToEmail@yahoo.co.in", "RDBurmon", @"E:\File.xlsx");







非常重要 -

请注意,gmail帐户安全性有重大变化,因此根据更改,您必须遵循吹制步骤才能从外部gmail门户发送邮件






VERY important-
Please note that there are substantial changes in gmail account security so as per the changes, you have to follow blow steps in order to send mail from out side gmail portal

1. Login to your gmail account.
2. Visit this page https://accounts.google.com/DisplayUnlockCaptcha and click on button to allow access.
3. Visit this page https://www.google.com/settings/security/lesssecureapps and enable access for less secure apps.


这篇关于发送邮件显示按摩的问题是发送邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆