Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data can be sent from cells, for example C2:H5, and the recipient receives a letter with the rows arranged like this:
how they are located and at the sender, and not in one line.
Thank you. - Sub Send_Mail()
-
Const CDO_Cnf = "http://schemas.microsoft.com/cdo/configuration/"
-
Dim oCDOCnf As Object, oCDOMsg As Object
-
Dim SMTPserver As String, sUsername As String, sPass As String, sMsg As String
-
Dim sTo As String, sFrom As String, sSubject As String, sBody As String, sAttachment As String
-
On Error Resume Next
-
'sFrom - как правило совпадает с sUsername
-
SMTPserver = [B10] ' SMTPServer: для Mail.ru "smtp.mail.ru"; для Яндекса "smtp.yandex.ru"; для Рамблера "mail.rambler.ru"
-
sUsername = [B11] ' Учетная запись на сервере
-
sPass = [B12] ' Пароль к почтовому аккаунту
-
-
If Len(SMTPserver) = 0 Then MsgBox "Не указан SMTP сервер", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
If Len(sUsername) = 0 Then MsgBox "Не указана учетная запись", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
If Len(sPass) = 0 Then MsgBox "Не указан пароль", vbInformation, "www.Excel-VBA.ru": Exit Sub
-
-
sTo = [B2] 'Кому
-
sFrom = [B3] 'От кого
-
sSubject = [B4] 'Тема письма
-
sBody = [B5] 'Текст письма
-
sAttachment = [B6] 'Вложение(полный путь к файлу)
-
-
'Назначаем конфигурацию CDO
-
Set oCDOCnf = CreateObject("CDO.Configuration")
-
With oCDOCnf.Fields
-
.Item(CDO_Cnf & "sendusing") = 2
-
.Item(CDO_Cnf & "smtpauthenticate") = 1
-
.Item(CDO_Cnf & "smtpserver") = SMTPserver
-
'если необходимо указать SSL
-
'.Item(CDO_Cnf & "smtpserverport") = 465 'для Яндекса и Gmail 465
-
'.Item(CDO_Cnf & "smtpusessl") = True
-
'=====================================
-
.Item(CDO_Cnf & "sendusername") = sUsername
-
.Item(CDO_Cnf & "sendpassword") = sPass
-
.Update
-
End With
-
'Создаем сообщение
-
Set oCDOMsg = CreateObject("CDO.Message")
-
With oCDOMsg
-
Set .Configuration = oCDOCnf
-
.BodyPart.Charset = "koi8-r"
-
.From = sFrom
-
.To = sTo
-
.Subject = sSubject
-
.TextBody = sBody
-
'Проверка наличия файла по указанному пути
-
If Len(sAttachment) > 0 Then
-
If Dir(sAttachment, 16) <> "" Then
-
.AddAttachment sAttachment
-
End If
-
End If
-
.Send
-
End With
-
-
Select Case Err.Number
-
Case -2147220973: sMsg = "Нет доступа к Интернет"
-
Case -2147220975: sMsg = "Отказ сервера SMTP"
-
Case 0: sMsg = "Письмо отправлено"
-
Case Else: sMsg = "Ошибка номер: " & Err.Number & vbNewLine & "Описание ошибки: " & Err.Description
-
End Select
-
MsgBox sMsg, vbInformation, "www.Excel-VBA.ru"
-
Set oCDOMsg = Nothing: Set oCDOCnf = Nothing
-
End Sub
-
-
'---------------------------------------------------------------------------------------
-
' Procedure : Get_File_Path
-
' Purpose : Процедура выбора файла
-
'---------------------------------------------------------------------------------------
-
Sub Get_File_Path()
-
Dim sPath
-
sPath = Application.GetOpenFilename("All Files(*.*),*.*", , "Выбрать файлы", "Выбрать", False)
-
If sPath = False Then Exit Sub
-
[B6] = sPath
-
End Sub
0 11205 Sign in to post your reply or Sign up for a free account.
Similar topics
by: >>Shailesh |
last post by:
hi,
my script(IMAP email client) is sending mail using imap_mail()
function.
imap_mail($To, $Subject, $Body, $headers);
$headers = "From: <$From>\n";
$headers .= "X-Sender:...
|
by: HoustonComputerGuy |
last post by:
I am working on getting my web applications moved to .Net 2.0 and am
having some problems with System.Net.Mail. I get the following error
when sending the mail:
System.Net.Mail.SmtpException was...
|
by: at |
last post by:
Hi,
I need to test a mail function through my IPS, who doesn't allow sending
mail without a password. Where do I specify this password? In php.ini I
can specify SMTP and sender, but apparently...
|
by: HK |
last post by:
In VB.NET, I'm getting the exception "failure sending mail". I'm running VS
2005 on XP Home. This is a new install on a new PC. I've never had email
problems with VS 2003, and there I could...
|
by: Zile |
last post by:
I am trying to send mail from web page in asp.net 2.0/VB 2005:
Dim Poruka As New System.Web.Mail.MailMessage
myMessage.From = "matematic@gmail.com"
myMessage.To = "matematic@hotmail.com"...
|
by: mkadasi |
last post by:
Hello Everyone,
I facing a problem in sending mail through vb.net.
The code written below sends the mail to the respective person specified in the 'TO' address. But the problem is that the...
|
by: satnamsarai |
last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail.
Unable to write data to the transport connection: An existing
connection was forcibly closed by the remote host.' Not sure how...
|
by: Danny |
last post by:
Hi all,
Trying to send mail with System.Net.SmtpClient, using very simple code
just for testing:
SmtpClient smtp = new SmtpClient("mail.server.com", 25);
smtp.Credentials = new...
|
by: JoeP |
last post by:
Hi All,
How can I find the reason for such an error: Failure sending mail.
Some Code...
oMailMessage.IsBodyHtml = False
oMailMessage.Body = cEmailBody
Dim oSMTP As New SmtpClient...
|
by: TanuLamba15 |
last post by:
Hi All,
Can anyone guide me I want to send attachment with my mail and I'm using http://demo.tutorialzine.com/2013/05/mini-ajax-file-upload-form/ plugin instead of simple <input type="file"/>, the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |